Filling two datagrids from two SELECTS in one DataSet

Discussion in 'ASP .Net' started by DC Gringo, Feb 26, 2004.

  1. DC Gringo

    DC Gringo Guest

    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
    DC Gringo, Feb 26, 2004
    #1
    1. Advertising

  2. 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
    =?Utf-8?B?U3VyZXNo?=, Feb 26, 2004
    #2
    1. Advertising

  3. DC Gringo

    Nikhil Patel Guest

    Hi,
    You can use Tables collection of the dataset.


    "DC Gringo" <> wrote in message
    news:O4QInAL$...
    > 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
    >
    >
    Nikhil Patel, Feb 26, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. savvy
    Replies:
    1
    Views:
    1,561
    Winista
    Mar 15, 2006
  2. Jim
    Replies:
    0
    Views:
    294
  3. Jules
    Replies:
    6
    Views:
    139
    Jules
    Jul 15, 2003
  4. Mohsen Pahlevanzadeh
    Replies:
    0
    Views:
    109
    Mohsen Pahlevanzadeh
    Sep 9, 2013
  5. MRAB
    Replies:
    0
    Views:
    108
Loading...

Share This Page