views:

152

answers:

2

How to fill multiple tables in a dataset.

I m using a query that returns me four tables.

At the frontend I am trying to fill all the four resultant table into dataset.

Here is my Query. Query is not complete. But it is just a refrence for my Ques

Select * from tblxyz compute sum(col1)

suppose this query returns more than one table, I want to fill all the tables into my dataset

I am filling result like this

con.open();
adp.fill(dset);
con.close();

Now when i checks this dataset. It shows me that it has four tables but only first table data is being displayed into it. rest 3 dont even have schema also.

What i need to do to get desired output

A: 

Check this links.

http://www.developer.com/article.php/3311341

http://vb.net-informations.com/dataset/dataset-multiple-tables-sqlserver.htm

Maybe the problem is that you need to return all your tables separetly, as different queries, for example, fill-ing the same DataSet in a loop.

Good Luck!

hgulyan
My single Query is returning me four tables. How would i store them all into dataset because i cant even loop here.
Shantanu Gupta
Try calling fill 4 times, adding table name to each call like this adapter.Fill(ds, "TableName")
hgulyan
+1  A: 

Use DataAdapter.TableMappings. e.g. :

        DataSet ds = new DataSet();
        // setup DataSet if required

        SqlCommand cmd = new SqlCommand();
        // setup command

        SqlDataAdapter da = new SqlDataAdapter(cmd);

        da.TableMappings.Add("Table", "goofy");
        da.TableMappings.Add("Table1", "donald");
        da.TableMappings.Add("Table2", "daffy");
        da.TableMappings.Add("Table3", "foghorn");

        da.MissingSchemaAction =  MissingSchemaAction.AddWithKey;
        da.Fill(ds);

where "goofy" is the name of the DataTable you want your first result set to go into, and "donald" is the second etc.

Moe Sisko