开发者

Single Query returning me 4 tables, How to get all of them back into dataset?

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开发者_Python百科 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


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.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜