|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataGrid ControlIm 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 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 Show quoteHide quote "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 > 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 Show quoteHide quote "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 > > 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 Show quoteHide quote "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 > > > 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 Show quoteHide quote "Peter Newman" <PeterNew***@discussions.microsoft.com> schreef in bericht news:F47A0C83-C97C-4785-9477-36C8A9FBEE08@microsoft.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 >> >
How to Automatically Update UI When Data Changes
HelpCursor on ToolStripMenuItem API Help in saving database How do I use a class, when the class requires functions in the main form? How to connect to database Process.start explorer in popup Error while file copying over network. Shortening my source. Shell IE ? |
|||||||||||||||||||||||