DataAdapter and passing query string question

S

stephen

Hi,

I know that you can pass 2 query strings into a dataadapter and fill a
dataset with 2 tables like this:

System.Data.SqlClient.SqlConnection con = new
System.Data.SqlClient.SqlConnection(Conn);
System.Data.SqlClient.SqlDataAdapter sda1 =
new System.Data.SqlClient.SqlDataAdapter("select ShipperID, CompanyName,
Phone, RegionDescription " +
"from shippers", con);
System.Data.SqlClient.SqlDataAdapter sda2 =
new System.Data.SqlClient.SqlDataAdapter("SELECT EmployeeID, lastname,
firstname " +
"FROM Employees", con);
sda1.Fill(ds, "TableShippers");
sda2.Fill(ds, "TableEmployees");

and use it like grid1.datasource = ds.tables["TableShippers"] or
ds.tables["TableEmployees"]

........
but i came accross an interesting code (pretty sweet...) that instead of 2
adapters you can pass the 2 queries in the same adapter and it works

System.Data.SqlClient.SqlConnection con = new
System.Data.SqlClient.SqlConnection(Conn);
System.Data.SqlClient.SqlDataAdapter sda =
new System.Data.SqlClient.SqlDataAdapter("select ShipperID, CompanyName,
Phone, RegionDescription " +
"from shippers;" +
"SELECT EmployeeID, lastname, firstname FROM Employees",
con);

if I use it like this grid1.datasource = ds.tables[0] or ds.tables[1] it
displays the appropriate data but if i use
ds.tables["TableShippers"] or ds.tables["TableEmployees"] if always binds to
ds.tables["TableShippers"]

why? and how can i use it by given table names?

I tried
sda.Fill(ds, "TableShippers");
sda.Fill(ds, "TableEmployees");

(...felt this syntax is not right but still defaults to shippers....)


Any ideas,
Stephen
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top