Filling two datagrids from two SELECTS in one DataSet

D

DC Gringo

This code has two SELECT statements, each returning several records. I want
to fill a dataset and then two datagrids. How would I fill the SECOND
datagrid from this code


-----

Sub BindSQL()
Dim MyConnection As SqlConnection
Dim DS as DataSet
Dim MyCommand As SqlDataAdapter
Dim RcdCount As Integer

'Our SQL string
Dim sqlStr As String = "SELECT title FROM authors SELECT au_lname FROM
authors"

'The connection to our database
Dim strConn As String = "server=(local);uid=sa;pwd=;" & _
"database=pubs;Trusted_Connection=yes;"



Next we need to instantiate our connection and command object, and the fill
our DataSet object with the results of the SQL query:
...

'Open up our connection with our connection object
MyConnection = New SQLConnection(strConn)

'To execute our Sql Statement and provide our active connection
MyCommand = NewSqlDataAdapter(sqlStr, MyConnection)

'Create instance of DataSet object and fill our predetermined
'datagrid with it and we name it
DS = new DataSet()
MyCommand.Fill(DS, "pubs")
 
G

Guest

You have to have 2 datatables in the dataset to do what you want

When you do this.
MyCommand.Fill(DS, "pubs"
even if you have 2 queries ADO.NET will merge the result sets into one Datatable

So what you have to do is execute the fill command one at a time for each select queries that you have. Also use different table names in the Fill method call (i.e. "pubs1", "pubs2", etc)

Then bind the 2 datatables seperately to your datagrids

Suresh


----- DC Gringo wrote: ----

This code has two SELECT statements, each returning several records. I wan
to fill a dataset and then two datagrids. How would I fill the SECON
datagrid from this cod


----

Sub BindSQL(
Dim MyConnection As SqlConnectio
Dim DS as DataSe
Dim MyCommand As SqlDataAdapte
Dim RcdCount As Intege

'Our SQL strin
Dim sqlStr As String = "SELECT title FROM authors SELECT au_lname FRO
authors

'The connection to our databas
Dim strConn As String = "server=(local);uid=sa;pwd=;" &
"database=pubs;Trusted_Connection=yes;



Next we need to instantiate our connection and command object, and the fil
our DataSet object with the results of the SQL query
..

'Open up our connection with our connection objec
MyConnection = New SQLConnection(strConn

'To execute our Sql Statement and provide our active connectio
MyCommand = NewSqlDataAdapter(sqlStr, MyConnection

'Create instance of DataSet object and fill our predetermine
'datagrid with it and we name i
DS = new DataSet(
MyCommand.Fill(DS, "pubs"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top