bind multiple data tables from sql queries to multiple datacontainers?

Discussion in 'ASP .Net' started by Daves, Jan 5, 2006.

  1. Daves

    Daves Guest

    a SQL query can return multiple data tables eg
    SELECT expression1 ...
    SELECT expression2 ...

    Can I in ASP.Net utilise this to do fewer data fetches from the server, e.g.
    selectively binding table1 to gridview1, table2 to gridview2 etc?
    Daves, Jan 5, 2006
    #1
    1. Advertising

  2. Daves,

    The short answer is yes.

    I'm sure there will be a few changes with .NET 2.0 but here's how I did it
    in .NET 1.1:

    Dim SqlCommand As New SqlClient.SqlCommand
    SqlCommand.CommandText = "SELECT * FROM authors; SELECT * FROM publishers"
    SqlCommand.CommandType = CommandType.Text
    SqlCommand.Connection = SqlConnection1

    Dim DataAdapter As New SqlClient.SqlDataAdapter(SqlCommand)

    Dim DataSet As New DataSet
    DataAdapter.Fill(DataSet)

    DropDownList1.DataSource = DataSet.Tables(0)
    DropDownList1.DataTextField = "au_lname"
    DropDownList1.DataValueField = "au_id"
    DropDownList1.DataBind()

    DropDownList2.DataSource = DataSet.Tables(1)
    DropDownList2.DataTextField = "pub_name"
    DropDownList2.DataValueField = "pub_id"
    DropDownList2.DataBind()

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Daves" <> wrote in message
    news:%...
    >a SQL query can return multiple data tables eg
    > SELECT expression1 ...
    > SELECT expression2 ...
    >
    > Can I in ASP.Net utilise this to do fewer data fetches from the server,
    > e.g. selectively binding table1 to gridview1, table2 to gridview2 etc?
    >
    S. Justin Gengo, Jan 6, 2006
    #2
    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. John
    Replies:
    1
    Views:
    284
    =?Utf-8?B?VG9Kbw==?=
    Jul 1, 2004
  2. mr2_93
    Replies:
    1
    Views:
    3,580
    mr2_93
    Oct 2, 2005
  3. Ian Roddis

    xslt queries in xml to SQL queries

    Ian Roddis, Feb 26, 2006, in forum: Python
    Replies:
    3
    Views:
    1,468
    Crutcher
    Feb 26, 2006
  4. ecoolone
    Replies:
    0
    Views:
    742
    ecoolone
    Jan 3, 2008
  5. Abby Lee

    so many queries within queries I'm confused

    Abby Lee, Aug 4, 2004, in forum: ASP General
    Replies:
    11
    Views:
    336
    Aaron [SQL Server MVP]
    Aug 6, 2004
Loading...

Share This Page