Arun Singh
Can we load multiple tables in a Dataset? How?
By Arun Singh in ADO.NET on Jul 04 2012
  • Vinoth Srinivasan
    Feb, 2013 4

    Yes!We can load multiple tables in a dataset. This is the main advantage of using a dataset. DataSet dSet=new DataSet(); SqlConnection connection=new SqlConnection("your connection string"); SqlDataAdapter adapter=new SqlDataAdapter("select * from table1",connnection); adapter.Fill(dSet.Tables.Add()); adapter=new SqlDataAdapter("select * from table2",connnection); adapter.Fill(dSet.Tables.Add()); After adding the tables to a dataset, the following code describes how to make use of the dataset tables. If you want to make use of the first table in a dataset or if you want to copy that table data into a datatable,write as follows DataTable dt=new DataTable() dt=dSet.Tables[0]; The above code used to add tables in a dataset as much required.This scenario ensures the connectionless data access. Since the dataset is filled with many tables there is no need to have a database connection for every time we want to query the data and it also ensures the reusability of data.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS