how can I make the dataadapter to return multiple recordsets?

  • Thread starter Thread starter younker
  • Start date Start date
Y

younker

I want to use adapter.Fill(ds); to get the data result,
and I hope this can contain two or more recordsets in the
dataset, then I can use ds.tables to access the
different recordsets.

thanks
 
Recordsets do not exist in ADO.NET anymore. You do have DataTables which
provide a disconnected mechanism to access data. DataTable basically is the
in-memory representation of your the resultset derived from your query.
Your DataSet can contain two DataTables. And yes you can use ds.tables to
access the DataTable.
 
If you're working with a database and provider that support
returning multiple resultsets, then you can accomplish this with
a DataAdapter.

string strConn, strSQL;
strConn = "Provider=SQLOLEDB;Data Source=(local);" +
"Initial Catalog=Northwind;Trusted_Connection=Yes;";
strSQL = "SELECT CustomerID, CompanyName FROM Customers " +
"WHERE CustomerID LIKE 'A%';" +
"SELECT OrderID, CustomerID, OrderDate FROM Orders " +
"WHERE CustomerID LIKE 'A%'";
OleDbDataAdapter da = new OleDbDataAdapter(strSQL, strConn);
DataSet ds = new DataSet();
da.Fill(ds);


You can also use the DataAdapter's TableMappings collection
to control the name of the DataTables that the DataAdapter
creates/uses.

da.TableMappings.Add("Table", "Customers");
da.TableMappings.Add("Table1", "Orders");


I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.
 
Back
Top