I need to split datatable into two datatables based on Group by and another column values.
From the Source Datatable, I need to move records based on Group by columns “Col 1” and “Col 2”. In addition, if the values in the “Col 3” contains “I” & “A”, then the set of records should be moved to new datatable (DT1). And rest of the Source Datatable should be moved to another new datatable (DT2). Please help me to solve this.
What I have:
Source Datatable:
What I need:
In a New Datatable (DT1):
and
In a New Datatable (DT2):
Since dealing with datatable with large data, I am trying in LinQ Query instead of For Each loop:
(from d in readExcel.AsEnumerable Where (d(0).ToString.Equals("One") And d(1).ToString.Equals("10")) Or (d(0).ToString.Equals("Two") And d(1).ToString.Equals("20")) Select d).CopytoDatatable
Output :-
Linq for DT2 :-
(from d in readExcel.AsEnumerable Where (d(0).ToString.Equals("One") And d(1).ToString.Equals("20")) Or (d(0).ToString.Equals("Two") And d(1).ToString.Equals("10")) Select d).CopytoDatatable