bind multiple data tables from sql queries to multiple datacontainers?

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?
 
S

S. Justin Gengo

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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top