How can we load multiple tables into Dataset?
How can we load multiple tables into Dataset
Hi all,
How can we load multiple tables into Dataset?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Posted Jun 9, 2011, 11:11 PM EDT
select * from table1
select * from table2 etc.
This will create two tables inside the database.
You can manually also create datatable and add it into the dataset.
Pradeep ChandrakerRank #941 · 2.2K reputationPosted Jun 10, 2011, 9:52 AM EDT
DataSet ds = new DataSet();
DataTable dt1 = new DataTable();
ds.Tables.Add(dt1);
DataTable dt2 = new DataTable();
ds.Tables.Add(dt2);
Sam HobbsRank #107 · 20.5K reputationPosted Jun 11, 2011, 2:12 PM EDT
raghu v52 reputationPosted Jun 13, 2011, 12:36 AM EDT
the previous answers are clear to explain u doubt and if u are still in confusion i hope u know how to fill the data set using dataadaptor then u can follow the following way to store multi results in a data set
sqldatadataptor da = new sqldataadaptor("select * from table1","conn");
dataset ds= new dataset();
da.fill(ds,"table1");// here table1 is the virtual table name for the result set 1
da=new sqladaptor("select * from table2","conn");
da.fill(ds,"table2");//here table2 is virtual table name for the result set 2
now u can get the data from which ever table set u desired
gridview grdview1 =new gridview();
gridview1.datasource=ds.tables["table1"];//if u want to use table1
gridview1.datasource = ds.tables["table2"];//if u want to use table 2
Note:if u just bind fill the data in to dataset with out virtual names then u can access ur table from data set using index
like grdview1.datasource=ds.tables[0];/ds.tables[1]'