Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Filling two datagrids from two SELECTS in one DataSet

Reply
Thread Tools

Filling two datagrids from two SELECTS in one DataSet

 
 
DC Gringo
Guest
Posts: n/a
 
      02-26-2004
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")





--
_____
DC G


 
Reply With Quote
 
 
 
 
=?Utf-8?B?U3VyZXNo?=
Guest
Posts: n/a
 
      02-26-2004
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"





--
____
DC



 
Reply With Quote
 
 
 
 
Nikhil Patel
Guest
Posts: n/a
 
      02-26-2004
Hi,
You can use Tables collection of the dataset.


"DC Gringo" <(E-Mail Removed)> wrote in message
news:O4QInAL$(E-Mail Removed)...
> 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")
>
>
>
>
>
> --
> _____
> DC G
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
join two selects gert Python 2 05-21-2009 11:17 PM
Filling Datagrids based on dropdown Jim ASP .Net 0 11-07-2007 04:54 PM
Problem of two tables while filling DataSet savvy ASP .Net 1 03-15-2006 05:48 PM
Duwamish Framework--Filling DataSet Paul ASP .Net 2 08-09-2003 11:54 PM
Newbie SQL question: Break SQL into different SELECTs or keep as one Jules ASP General 6 07-15-2003 12:47 PM



Advertisments