bind multiple data tables from sql queries to multiple datacontainers?

  • Thread starter Thread starter Daves
  • Start date Start date
D

Daves

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,

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
 
Back
Top