How to sort data table by two columns? sort data table on one column and sort data table on another column not working.
It’s always good to search the forum before posting.
1 Like
Thank you, @postwick
Is there a way I can split the data table into multiple data tables that are grouped by a column name?’
May be this should be a separate question.
Thank you so much,
dtdata is your datatable name
dtdata.AsEnumerable() _
.OrderBy(Function(row) row.Field(Of String)("FirstColumn")) _
.ThenBy(Function(row) row.Field(Of String)("SecondColumn")) _
.CopyToDataTable()
Please Kindly note this:-
- If the column types are different, replace
String
with the appropriate data type (e.g.,Int32
for integers,DateTime
for dates). - Ensure
dtdata
is not empty to avoid exceptions. You might want to check ifdtdata.Rows.Count > 0
before sorting.
1 Like
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.