Is there any way to sort the data table by character type numbers?

I’m currently trying to sort DataTable values by the NO column, but since the NO is a string number, I’m having problems sorting by referring to the first digit as 1, 10, 100.

I would like to change this so that it simply lines up in numerical order, 1, 2, 3, etc. Is there any good way to do this?

By the way, I used the SortDataTable Activity, but the order was 1, 10, 100 as shown above.

Therefore, I tried the following URL here as my next method, but I am getting an error.

dt1.AsEnumerable.OrderBy(Function(r) If(IsNumeric(r(“columnname”)), CDbl(r(“columnname”)), 0)).CopyToDatable

The error contents are as follows
It is not possible to refer to an instantiated member of a class from a shared method or shared member initialization without specifying an explicit instance of the class.

No inference can be made from these arguments. Making the data explicit may fix this error.

Since I don’t know how to solve the above error, I am not sure how to counter it.

Therefore, what is the best way to sort the No. in the data table as a number under this situation?

Thank you very much for your help.


It seems namespace matter. Can you try the following expression?

dt1.AsEnumerable.OrderBy(Function(r) If(Microsoft.VisualBasic.Information.IsNumeric(r("columnname")), CDbl(r("columnname")), 0)).CopyToDataTable()


1 Like

Thank you.
I was able to sort them in the correct numerical order.

1 Like

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