I want to sort my data table with ‘n’ number of columns. For this I have to pass the variable in my expression.I want to use below expression but it is limited to two columns only. datatablevariable = From x In datatablevariable.AsEnumerable() Order By convert.Tostring(x(“Column1")),convert.ToString(x(“Column2”)) Select x).CopyToDataTable
So you want to sort by one column only? Or you want to sort by column1, then by column2, and so on?
If it is the first, then no need for a complicated linq statement. You can just specify the single column you’d like to sort in the datatable instead of creating a new Select statement. Here is a stackoverflow question asking how to do that, along with multiple answers that would work fine: .net - Sorting a Data Table - Stack Overflow
If it is the second, then you should use the .Orderby method for the first sort, then each sort thereafter you specify (in order) with the .ThenBy method
I want to sort my data table with multiple columns. Also, column’s names by which I want to sort data table are given as a input by the user so they can be either 2 or 3 or more than that.
My issue is resolved now. Thanks for providing that stack overflow link.
I just used the Invoke code activity and put below two lines: datatableVar.DefaultView.Sort = (“Column1_name ASC, Column2_name ASC”) datatableVar = datatableVar.DefaultView.ToTable
Now, I can put any number of columns here.