This thread will help you to sort a column or Multiple Columns of Data Table using some simple techniques.
Suppose if we have a Data Table having 2 columns as shown below.
1. To Sort data in Ascending Order based on Column “KeyWord” using Linq Query :
Sort a column in Ascending Order using LinQ
Expression :
InputDt = (InputDt.AsEnumerable.OrderBy(Function(x) x(“KeyWord”).ToString)).CopyToDataTable
Result :
2. To Sort data in Descending Order based on Column “KeyWord” using Linq Query :
Sort a column in Descending Order using LinQ
Expression :
InputDt = (InputDt.AsEnumerable.OrderByDescending(Function(x) x(“KeyWord”).ToString)).CopyToDataTable
Result :
3. To Sort Data in Ascending order based on column “keyWord” using Sort Data Table Activity
Sort a Column using Sort Data Table Activity
Activity & It’s Property settings :
(In Properties panel Pass Input Datatable, Output Datatable, Column Name, Order)
4. To Sort the Data in ascending Order based on column “KeyWord” and in Descending Order based on column “EndDate”
Sort Multiple columns in different Order
Use Assign Activity and the expressions as below.
Assign InputDt.DefaultView.Sort = “[KeyWord] ASC, [EndDate] DESC”
Assign InputDt = InputDt.DefaultView.ToTable
Output :
Happy Automation!!
Thanks & Regards,
Rohith