Multiple Result Sets in a DataSet from DataAdapter ?

  • Thread starter Thread starter Liz
  • Start date Start date
L

Liz

Anyone have any info on how you can fill a DataSet with mutiple result sets
from a SQL batch ? I know with a dataReader you can use the nextResult
method but I'm lost on how you do this with a dataAdapter ....

TIA ..

L
 
You may want to do something like this in C# 2.0:

DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter("select * from authors;
select * from employee",

ConfigurationManager.ConnectionStrings["pubsConnectionString"].ConnectionString);
sda.Fill(ds);

gvAuthors.DataSource = ds.Tables[0]; //gvAuthors = GridView
control
gvAuthors.DataBind();

gvEmployees.DataSource = ds.Tables[1]; //gvEmployees = another
GridView control
gvEmployees.DataBind();
 
Hi,

DataAdapter.Fill will do it for you

From MSDN:
When handling batch SQL statements that return multiple results, the
implementation of FillSchema for the .NET Framework Data Provider for OLE DB
retrieves schema information for only the first result. To retrieve schema
information for multiple results, use Fill with the MissingSchemaAction set
to AddWithKey.

So it will create one table per resultset
 
Deepak Khanal said:
You may want to do something like this in C# 2.0:

DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter("select * from authors;
select * from employee",

ConfigurationManager.ConnectionStrings["pubsConnectionString"].ConnectionString);
sda.Fill(ds);

gvAuthors.DataSource = ds.Tables[0]; //gvAuthors = GridView
control
gvAuthors.DataBind();

gvEmployees.DataSource = ds.Tables[1]; //gvEmployees = another
GridView control
gvEmployees.DataBind();


so simple ... don't know why I didn't try that ... thanks ....

Liz
 
Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

DataAdapter.Fill will do it for you

From MSDN:
When handling batch SQL statements that return multiple results, the
implementation of FillSchema for the .NET Framework Data Provider for OLE DB
retrieves schema information for only the first result. To retrieve schema
information for multiple results, use Fill with the MissingSchemaAction set
to AddWithKey.

ok ... I'm still finding my way around with this stuff ... what's the
significance of this part of the picture ?

Liz
 
Back
Top