multiple tables in a DataSet
how to load multiple tables in a DataSet ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Jun 7, 2011, 3:32 PM
Do the tables already exist? I assume they do but it would help to state that explicitly.
Are the fields different for the two tables? I assume they are but it would help to state that explicitly.
If there are other issues such as Referential integrity then it would help to specify those too.
There are many ways to do what you are asking for help with so if you specify what you are familiar with then that will help too.
Suthish NairPosted Jun 7, 2011, 6:27 AM
Jiteendra SampathiraoPosted Jun 7, 2011, 6:23 AM
objCommand.CommandText = "Table1"
objDataAdapter.Fill(objDataSet, "Table1")
objCommand.CommandText = "Table2"
objDataAdapter.Fill(objDataSet, "Table2")
Above is a sample code which shows how to load multiple "DataTable" objects in one "DataSet" object.
Sample code shows two tables "Table1" and "Table2" in object ObjDataSet.
lstdata.DataSource = objDataSet.Tables("Table1").DefaultView
In order to refer "Table1" DataTable, use Tables collection of DataSet and the Defaultview object will give you the necessary output.
Source: Sivaprasad Koirala Interview book
Mayur GujrathiPosted Jun 7, 2011, 3:22 AM
in which situation you want to add tables in dataset
Posted Jun 7, 2011, 3:14 AM
DataSet.Tables.Add(yourDataTable2)
otherwise you can do two or more select statements from your sp...
Praneeth KumarPosted Jun 7, 2011, 2:50 AM