Wednesday, 31 July 2013

C# - How to add DataTable to DataSet and DataSet to DataTable in asp.net?


Dataset

DataSet objects are in-memory representations of data. They contain multiple Datatable objects, which contain columns and rows, just like normal database tables. You can even define relations between tables to create parent-child relationships. The DataSet is specifically designed to help manage data in memory and to support disconnected operations on data, when such a scenario make sense. The DataSet is an object that is used by all of the Data Providers, which is why it does not have a Data Provider specific prefix.


Data Table

Data table is a collection of records that consist the single table. You can get dataTable from dataset as follows.


Example: Add DataTable to DataSet

        DataTable employeesInfo = new DataTable();
        DataTable payCheckesInfo = new DataTable();
        DataSet ds = new DataSet();
        ds.Tables.Add(employeesInfo);
        ds.Tables.Add(payCheckesInfo);

Example: Add DataSet to DataTable
DataSet ds = new DataSet();
DataTable DataTable2 = new DataTable();
DataTable2 = ds.Tables[0].Clone();

No comments:

Post a Comment