Sort data table by two columns A, B

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:-

  1. If the column types are different, replace String with the appropriate data type (e.g., Int32 for integers, DateTime for dates).
  2. Ensure dtdata is not empty to avoid exceptions. You might want to check if dtdata.Rows.Count > 0 before sorting.
1 Like

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