Sort Datatable and Create new Datatable based on Sorting results

Hi All,

I am looking for help here in one of the requirement where i have to Sort the data table first and then create new data table based on sorting results.

For e.g
Emp ID Emp Name Department
1 abc Automation
2 def Testing
3 ghi R&D
4 jkl Automation
5 mno Testing
6 pqr R&D

Now in above case BOT first should sort based on Department
For e.g.
Emp ID Emp Name Department
1 abc Automation
4 jkl Automation
2 def Testing
5 mno Testing
3 ghi R&D
6 pqr R&D

and then create 3 new data table like below based on Sort results

Datable 1
Emp ID Emp Name Department
1 abc Automation
4 jkl Automation

Datatable 2
Emp ID Emp Name Department
2 def Testing
5 mno Testing

Datatable 3
Emp ID Emp Name Department
3 ghi R&D
6 pqr R&D

Please note i have already tried below

dtNewTest= dtTest.DefaultView.ToTable(true,“Department”)

dtNewTest2=dtTest.Clone

for each CurrentRow in dtNewTest
dtNewTest2= dtTest.Select(“[Department]='”+Convert.ToString(CurrentRow.Item(“Department”))+“'”).CopyToDataTable

Above worked as expected if i hardcode the Department value but as soon as i pass variable to it, i get an error “The source contains no DataRows.”

Assign Activity
TableList | DataType: List(Of DataTable) =

From d in YourDataTableVar.AsEnumerable
Group d by k=d("Department").toString.Trim into grp=Group
Select t = grp.CopyToDataTable).toList

where the described NON LINQ Approach is working with the DefaultView

Sorry for late reply. but Thanks a lot… It saved my day

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.