Sort by use linq

I want tot sort date (old to new) column Planned Start in datatable dt_result but error as below.

Please guide me for solve it,

Thank you.

Hi @Stef_99

Try this:

dt_Result.AsEnumerable().OrderBy(Function(row) row.Field(Of DateTime)("Planned Start")).CopyToDataTable()


1 Like

Hi @Stef_99 ,

Sorting the data table based on particular column name
dt = dt.Select("",[ColumnName] asc").CopyToDataTable()


we would recommend to go through the statement and understanding what was intended, but what was coded

For LINQ in General:
[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum

OrderBy Operator:

When using defaultView.ToTable method, the second method parameter is a string array with the column names

dt_Result.Columns.Cast(Of DataColumn)…wil return a collection of DataColumns

  • but not the name
  • but as IEnumerable and not as Column name string array

.AsEnumerable - obsolete, as Cast was used

.OrderBy -

  • is still applied to collection of DataColumns
  • there is no available column value access concept

Also with the intention of selecting a particular column value with DatarowVar(ColNameOrIndex) we will get returned value of DataType: Object. But in the majority, we are interested in an ordering which is related to the DataType (Text - lexically, Numbers - numerical, Dates - …). Therefore the Object value has correctly cast / converted / transformed into the needed datatype

For Fixings:
dtResult-DefaultView.ToTable(False, → Your String Array with ColumnNames <-)
Apply the AsEnumerable on the resulting DataTable
Order the rows (LINQ, Non-Linq)

1 Like

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