Adding to a DataSet

  • Thread starter Thread starter Chris Dunaway
  • Start date Start date
C

Chris Dunaway

Since I cannot seem to find another group for posting ADO.Net
questions, I'll ask here.

I can create a query that will return a DataSet with one or more tables
in it. Is it possible to execute a query and "add" a table to the
DataSet?

For example, suppose during the process I issue a query that returns a
DataSet with a table that contains Customers in it. Now I want to
issue an additional query that will get Customer Orders but I want this
new DataTable to be added to the existing DataSet. I may further want
to get Order Details and add that table to the DataSet, all with their
appropriate data relations if possible.

How is this done?

Thanks,

Chris
 
For example, suppose during the process I issue a query that returns a
DataSet with a table that contains Customers in it. Now I want to
issue an additional query that will get Customer Orders but I want this
new DataTable to be added to the existing DataSet.

Yes, of course you can do this! If you have an existing DataSet with a
DataTable "tblCustomers", and you need to add the orders, you would
use ADO.NET's SqlDataAdapter and a SQL query / stored proc as its
"SelectCommand", to retrieve the customer orders, and then you'd call:

mySqlDataAdapter.FillDataSet(dsYourDataSet, "tblOrders")

and you end up with your data set having two tables inside it, one
called "tblCustomers" and another one "tblOrders".

Marc
================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
 
Chris,

You can add as much tables in a dataset as you want.

However they need to have a name and with that you have to watch that you
cannot set a relation when there is no table with that name.

As well can you not have missing child parent relations.

This in general.

Cor
 
Back
Top