473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

DataGrid Control

Im just toying with vb.net and am trying to find out howw things work. i
have managed to come up with the following code that will access a table in a
sql2005 server . what id like to do is populate 'DataGrid1' with the results
can anybody explain how this is done

STR_SQLQuery = "select LICENCE, COMPANYNAME from
DevSys.dbo.clientAdmin "
STR_SQLCOMMAND.CommandText = STR_SQLQuery
STR_SQLCOMMAND.Connection = CON_BOSSCONNECTION
STR_SQLREADER = STR_SQLCOMMAND.ExecuteReader
Try
While STR_SQLREADER.Read()
Console.WriteLine(STR_SQLREADER.GetString(0) & " " &
STR_SQLREADER.GetString(1))
End While
Finally
STR_SQLREADER.Close()
End Try

Jun 7 '06 #1
4 1272
Peter,

You need to look into the DataAdapter, DataSet and DataTable classes.

Use a dataadapter to fill a dataset's datatable with the results of your sql
select query.

Then assign the dataset's datatable to the datagrid's DataSource property.

Kerry Moorman
"Peter Newman" wrote:
Im just toying with vb.net and am trying to find out howw things work. i
have managed to come up with the following code that will access a table in a
sql2005 server . what id like to do is populate 'DataGrid1' with the results
can anybody explain how this is done

STR_SQLQuery = "select LICENCE, COMPANYNAME from
DevSys.dbo.clientAdmin "
STR_SQLCOMMAND.CommandText = STR_SQLQuery
STR_SQLCOMMAND.Connection = CON_BOSSCONNECTION
STR_SQLREADER = STR_SQLCOMMAND.ExecuteReader
Try
While STR_SQLREADER.Read()
Console.WriteLine(STR_SQLREADER.GetString(0) & " " &
STR_SQLREADER.GetString(1))
End While
Finally
STR_SQLREADER.Close()
End Try

Jun 7 '06 #2
Kerry,

I had a good look through the thread and came up with this funcction

Public Function SelectRows(ByVal dataSet As DataSet, ByVal queryString As
String) As DataSet
Dim adapter As New SqlClient.SqlDataAdapter
adapter.SelectCommand = New SqlClient.SqlCommand(queryString,
CON_BOSSCONNECTION)
adapter.Fill(dataSet)
Return dataSet
End Function

however it blows out at adapter.Fill(dataSet) with the following error

An unhandled exception of type 'System.ArgumentNullException' occurred in
system.data.dll

Additional information: Value cannot be null.

im calling it by using the following
dim REUSE_DATASET As DataSet

SelectRows(REUSE_DATASET, STR_SQLQuery)

this is all new to me and im totally confused now
"Kerry Moorman" wrote:
Peter,

You need to look into the DataAdapter, DataSet and DataTable classes.

Use a dataadapter to fill a dataset's datatable with the results of your sql
select query.

Then assign the dataset's datatable to the datagrid's DataSource property.

Kerry Moorman
"Peter Newman" wrote:
Im just toying with vb.net and am trying to find out howw things work. i
have managed to come up with the following code that will access a table in a
sql2005 server . what id like to do is populate 'DataGrid1' with the results
can anybody explain how this is done

STR_SQLQuery = "select LICENCE, COMPANYNAME from
DevSys.dbo.clientAdmin "
STR_SQLCOMMAND.CommandText = STR_SQLQuery
STR_SQLCOMMAND.Connection = CON_BOSSCONNECTION
STR_SQLREADER = STR_SQLCOMMAND.ExecuteReader
Try
While STR_SQLREADER.Read()
Console.WriteLine(STR_SQLREADER.GetString(0) & " " &
STR_SQLREADER.GetString(1))
End While
Finally
STR_SQLREADER.Close()
End Try

Jun 7 '06 #3
Peter,

dim REUSE_DATASET As NEW DataSet

You might also consider:

Public Function SelectRows(ByVal queryString As
String) As DataSet
Dim dataSet as New DataSet
Dim adapter As New SqlClient.SqlDataAdapter
adapter.SelectCommand = New SqlClient.SqlCommand(queryString,
CON_BOSSCONNECTION)
adapter.Fill(dataSet)
Return dataSet
End Function

Kerry Moorman
"Peter Newman" wrote:
Kerry,

I had a good look through the thread and came up with this funcction

Public Function SelectRows(ByVal dataSet As DataSet, ByVal queryString As
String) As DataSet
Dim adapter As New SqlClient.SqlDataAdapter
adapter.SelectCommand = New SqlClient.SqlCommand(queryString,
CON_BOSSCONNECTION)
adapter.Fill(dataSet)
Return dataSet
End Function

however it blows out at adapter.Fill(dataSet) with the following error

An unhandled exception of type 'System.ArgumentNullException' occurred in
system.data.dll

Additional information: Value cannot be null.

im calling it by using the following
dim REUSE_DATASET As DataSet

SelectRows(REUSE_DATASET, STR_SQLQuery)

this is all new to me and im totally confused now
"Kerry Moorman" wrote:
Peter,

You need to look into the DataAdapter, DataSet and DataTable classes.

Use a dataadapter to fill a dataset's datatable with the results of your sql
select query.

Then assign the dataset's datatable to the datagrid's DataSource property.

Kerry Moorman
"Peter Newman" wrote:
Im just toying with vb.net and am trying to find out howw things work. i
have managed to come up with the following code that will access a table in a
sql2005 server . what id like to do is populate 'DataGrid1' with the results
can anybody explain how this is done

STR_SQLQuery = "select LICENCE, COMPANYNAME from
DevSys.dbo.clientAdmin "
STR_SQLCOMMAND.CommandText = STR_SQLQuery
STR_SQLCOMMAND.Connection = CON_BOSSCONNECTION
STR_SQLREADER = STR_SQLCOMMAND.ExecuteReader
Try
While STR_SQLREADER.Read()
Console.WriteLine(STR_SQLREADER.GetString(0) & " " &
STR_SQLREADER.GetString(1))
End While
Finally
STR_SQLREADER.Close()
End Try

Jun 7 '06 #4
Peter,

Are you using VB2003 with WebForm or Winform or even something else?.

In a VB2003 WebForm you can bind a datareader to a DataGrid what is not
possible in a Winform where you have to follow the way as Kerry has
described.

Just as little addition,

Cor

"Peter Newman" <Pe*********@discussions.microsoft.com> schreef in bericht
news:F4**********************************@microsof t.com...
Kerry,

I had a good look through the thread and came up with this funcction

Public Function SelectRows(ByVal dataSet As DataSet, ByVal queryString
As
String) As DataSet
Dim adapter As New SqlClient.SqlDataAdapter
adapter.SelectCommand = New SqlClient.SqlCommand(queryString,
CON_BOSSCONNECTION)
adapter.Fill(dataSet)
Return dataSet
End Function

however it blows out at adapter.Fill(dataSet) with the following
error

An unhandled exception of type 'System.ArgumentNullException' occurred in
system.data.dll

Additional information: Value cannot be null.

im calling it by using the following
dim REUSE_DATASET As DataSet

SelectRows(REUSE_DATASET, STR_SQLQuery)

this is all new to me and im totally confused now
"Kerry Moorman" wrote:
Peter,

You need to look into the DataAdapter, DataSet and DataTable classes.

Use a dataadapter to fill a dataset's datatable with the results of your
sql
select query.

Then assign the dataset's datatable to the datagrid's DataSource
property.

Kerry Moorman
"Peter Newman" wrote:
> Im just toying with vb.net and am trying to find out howw things work.
> i
> have managed to come up with the following code that will access a
> table in a
> sql2005 server . what id like to do is populate 'DataGrid1' with the
> results
> can anybody explain how this is done
>
> STR_SQLQuery = "select LICENCE, COMPANYNAME from
> DevSys.dbo.clientAdmin "
> STR_SQLCOMMAND.CommandText = STR_SQLQuery
> STR_SQLCOMMAND.Connection = CON_BOSSCONNECTION
> STR_SQLREADER = STR_SQLCOMMAND.ExecuteReader
> Try
> While STR_SQLREADER.Read()
> Console.WriteLine(STR_SQLREADER.GetString(0) & " " &
> STR_SQLREADER.GetString(1))
> End While
> Finally
> STR_SQLREADER.Close()
> End Try
>

Jun 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
2
by: Carolyn Vo | last post by:
I have been looking and looking but can't seem to find out how to get the row selected in a web control datagrid (NOT a web form datagrid!!!), and how to highlight the selected row. I'm sure this...
3
by: Ryan Liu | last post by:
Hi there, I got a NullReferenceException when delete last row in a datagrid. I had hard time to solve since it does not occur in my own code. I put a datagrid in my inherited user control,...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
4
by: Glenn Owens | last post by:
I have a DataGrid web control which I've dynamically populated with template columns to be used for bulk-editting. Generally, all of the columns are textbox and/or dropdownlist child controls. ...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: Craig Banks | last post by:
If a row of data in a dataset has a lot of columns the row displaying the data in a datagrid will run way off the screen. What I'd like to do is display a row of data over several datagrid rows so...
1
by: thegame | last post by:
Filling One DataGrid Based on Selection from Another DataGrid - Both in Separate User Controls Hello, I have an interesting dilemma. I have an ASPX page with two user controls (two ASCXs). ...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
3
by: chreo | last post by:
Hello. I have datagrid. I found code to select all row in data grid (by mouse or arrow keys). This works great - user can select row and... ....and I want to go to next control. For...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.