locked
Split a datatable into two half RRS feed

  • Question

  • User1654552095 posted

    i want to split a DATATABLE into two parts using C#. can anyone tell me how to do that so i can using this two datatable ito two different repeter...I want the DATATABLE devided into two half....

    Means If i have 100 row in a table then two datatable consist of 50 50 row.....or in case of 101 it will be 51 and 50.....

    Thakning You

    Anirban

    Tuesday, November 20, 2012 2:32 AM

Answers

  • User-821857111 posted
    var totalRows = myDatatable.Rows.Count;
    var halfway = totalRows/2;
    var firstHalf = myDatatable.AsEnumerable().Take(halfway).CopyToDataTable();
    var secondHalf = myDatatable.AsEnumerable().Skip(halfway).Take(totalRows - halfway).CopyToDataTable();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 20, 2012 2:49 AM

All replies