Sort column in datatable

Hi Everyone.

I have two columns as below in datatable
Code, Quantity
Apple, 6

Lemon,8

Banana,9

I want to sort :

  1. Sort column"Quantity" ASC or DES

Code, Quantity

Banana,9

Lemon,8

Apple,6

  1. Sort alphabet column “Code”

Code, Quantity

Apple,6

Banana,9

Lemon,8

I have tried to use below code but not success might has error

DTout = (From row In DTout.Select Order By Convert.ToInt32(row(“Quantity”)) Descending Select row).ToArray.CopyToDatatable()

Thanks in advance!

@trunghai
the code is a little bit less readable formated, but wirll have some issues

Just decide if you want to go with method or expression syntax type of your statement
give a try on (Method syntax, maybe some brackets are to check)

DTout.AsEnumerable().OrderBy(Function (row) Convert.ToInt32(row(“Quantity”)).Select(Function (row) row).ToArray.CopyToDatatable()

3 Likes

Thanks you bro.

I have find out reason :slight_smile:

Perfect Happy Automation :+1:

1 Like

sorry bro.
How to sort with alphabet in one column

I have used below code to sort DES
(“[Quantity] ASC”)

1 Like

There is a Sort Data Table Activity, why you dont use this one?

1 Like

@trunghai

have look here on ASC, DESC, Second Sort.
I would try to let it derive by datatype: string=Alpha etc

1 Like

Thanks you so much @AntonWildermut & @ppr

I have used sort table activity :slight_smile:

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