Split datatable into multiple tables

Split datatable into multiple tables

Split datatable into multiple tables

I have a data table which has 1123 records. I want to split this table into 5 fixed size separate datatables. Size limit for each table is 225.I have dataset , that dataset having one datatable with values. I want to split datatable in to multiple datatable based on row values during for loop.Finally I need that dataset with multiple datatable. Split method for data.table. Faster and more flexible. Be aware that processing list of data.tables will be generally much slower than manipulation in single data.table by group using by argument, read more on data table.

DataSet ResultDataSet= new DataSet();
DataTable customers = myDataset.Tables.Add("Customers");

customers

.Columns.Add("Name");
customers
.Columns.Add("Age");

customers

.Rows.Add("Chris", "25");

int records=10;   // split the  10 records per table. if 50 records will be there then 5 tables will generate.

var splittedTables = ResultDataSet.AsEnumerable()
.Select((row, index) => new { row, index })
.GroupBy(x => x.index / records)
.Select(g => g.Select(x => x.row).CopyToDataTable())
.ToArray();

for Reference : Split datatable into multiple fixed sized tables

 

SHARE THIS

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.