[Solved] I want to Split Datatable rows based on number [closed]


You could use following LINQ query:

DataTable[] splittedtables = tbl.AsEnumerable()
    .Select((row, index) => new { row, index })
    .GroupBy(x => x.index / 12)  // integer division, the fractional part is truncated
    .Select(g => g.Select(x => x.row).CopyToDataTable())
    .ToArray();

The array contains 6 tables, 5 with 12 rows, the last one has the remaining row.

Checked with this sample-data:

DataTable  tbl = new DataTable();
tbl.Columns.Add("Column");
for(int i=0; i < 61; i++)
    tbl.Rows.Add(i.ToString()); 

You need to add using System.Linq;.

solved I want to Split Datatable rows based on number [closed]