How to sort the data using linq query

Hi All,

below query is not working for me.

i have excel file which has some columns and based on one column(Ageing) i want to sort the data in Ascendinh or Descending order.

(From row In dt_list.AsEnumerable
Order By Ageing(row.Item(2))Ascending Select row).copyToDataTable

Thanks

Hi @RAKESH_KUMAR_Tiwari ,

Try the below format:

InputDt = (InputDt.AsEnumerable.OrderByDescending(Function(x) x(“Ageing”).ToString)).CopyToDataTable

Regards,

2 Likes

@RAKESH_KUMAR_Tiwari

Please try this

Dt.AsEnumerable.OrderBy(function(x) Cdbl(x("Aging").ToString)).CopyToDataTable

Assuming all rows have data and they are numbers

Hope this helps

Cheers

1 Like

Hi @Anil_G ,

see the below error

Check this.

@RAKESH_KUMAR_Tiwari

Check the assembly reference or close …rename project.json and reopen

Cheers

i didn’t get it.

Please explain me step by step from start to end, what i need to do it.

You can fix it by adding the Assembly Reference manually in your xaml file: question- how to add it manually?
image

Simply open the file in Notepad and create new line with this String: question - which notepad file it is refering here
<AssemblyReference>System.Data.DataSetExtensions</AssemblyReference>

Then reopen your project and the error should be gone.

Please be careful while doing so and always keep a backup.

@RAKESH_KUMAR_Tiwari

First close your project…and rename the project.json file…then reopen the project and check if the issue is fixed

If not then open your xaml in notepad ++ and then just add the reference …that is highlighted in the picture and then re open…

For safety keep the file backedup

Cheers

but, i donot have option to rename the project.json file

image

@RAKESH_KUMAR_Tiwari

First step is to close ypur project…remaining steps are to be done using your file explorer not UiPath

Or just create a new project mostly that should work in the new peoject also. Issue is a package reference went missing in the references

Cheers

1 Like

i closed two times

@RAKESH_KUMAR_Tiwari

After closing …open the folder containing your project using a file explorer not the UiPath and the project menu that you get(no for this)

From the file explorer right click and rename

Cheers

Hi @Anil_G

i went to project folder through file explorer and rename the project.json again with same name, then i changed the Framework name also, but still there is error, but also i can see that after changing the framework work , it craeted another Project file.

project.json i renamed and then changed the framework name, after changing i can see it is created another project which of json type, img for reference.

@RAKESH_KUMAR_Tiwari

The purpose of changing the name is to let it create a new file and if possible it would automatically add references…as that did not happen

Now…open your xaml which is faulting in a notepad or notepad++ and add the assembly reference line for system.data.DataExtensions

Cheers

1 Like

Hi @Anil_G ,

i can see that error has gone now , but it is not sorted the data in any order either ascending or descending.

After function in x variable do i need to mention Ascending or descending?

@RAKESH_KUMAR_Tiwari

Ideally it would…can you confirm if the data in aeging is of type number?

And are you checking the right output table?

Cheers

sorry, my bad i was checking different dt table, now it giving me the output as Ascending order.
image

but what will be the query to fetch in Descending order? i want 40, 26, 18, 5

@RAKESH_KUMAR_Tiwari

Instead of Ordeby use OrderByDescending

Cheers

1 Like

ok thanks.

1 Like

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