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.
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
Praneeth KumarRank #4,422 · 344 reputationPosted Jun 6, 2011, 10:50 PM EDT
Posted Jun 6, 2011, 11:14 PM EDT
DataSet.Tables.Add(yourDataTable2)
otherwise you can do two or more select statements from your sp...
Mayur GujrathiRank #666 · 3.6K reputationPosted Jun 6, 2011, 11:22 PM EDT
in which situation you want to add tables in dataset
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted Jun 7, 2011, 2:23 AM EDT
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
Suthish NairRank #92 · 22.8K reputationPosted Jun 7, 2011, 2:27 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Jun 7, 2011, 11:32 AM EDT
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.