Datatable Filter Error

Hi Please help me on the issue.

Please find the attached.

I am filtering some data through Datatable but getting an error like, Cannot perform ‘<>’ operation on System.Double and System.String.

Help if anyone knows !

Thanks in advance

Hi @hemal

Can you share sample data? Or workflow

Also it looks like in the same column you are using String and Int both

Thanks,
Prankur

1 Like

Test.xaml (9.9 KB)

Please find the attached test file . You can create a simple excel file with the data ‘S1’ or ‘60’

thanks,
hemal.

Should I consider this as sample data?

image

I think this should work

dtop.Select("Subinventory='60' and Subinventory <> 'S1'").CopyToDataTable()

Thanks,
Prankur

1 Like

This works for me

dtop.Select("Subinventory='60' and Subinventory <> 'S1'").CopyToDataTable()

Also, I don’t understand the condition because you are filtering on the same column so there is no need to add not equals to condition :slight_smile: You can filter that by the first one only which will give you records that have SubInventory as 60

Thanks,
Prankur

2 Likes

Hi Prankur,

It was just testing purpose. So I added both the conditions. Ignore it. But the thing is, I am getting an issue. Even if i write only Subinventory <> ‘S1’ .

Thanks for your help.

I don’t understand what is wrong with my code !

Hi Prankur,

Please find the attached screenshot. I am getting this since yesterday! What’s wrong with it! Please help :frowning:

Thanks,
Hemal

1-31-2019.xlsx (7.8 KB)

Hi Prankur,

Please find the attached excel file and do it with read range activity

Thanks.

Remove the whole activity for filter and write it again. Also please make sure that quotes are correct, copy it from here

dtop.Select("Subinventory='60'").CopyToDataTable()

Thanks,
Prankur

1 Like

Thanks @prankur but still i’m facing. I have cleared and copied your code still i’m getting the same error.

Can you please check with the excel file once.

Thanks,
Hemal

I think, I am getting it. What I feel is, that Subinventory column data type should be changed in excel file.

Check this property in Read Range

image

If this not works along with this format excel column as Text, its working for me

Also in message box it should be

item(1).ToString

Because index starts from 0

Thanks,
Prankur

3 Likes

Try filter data table activity to get the results for both equal and Not equal parameters.

1 Like

Hey @PrankurJoshi,

Thank you so much :slight_smile: that property (PreserveFormat) was unchecked so i just checked and it is working fine !

Thank You so much :slight_smile:

1 Like

Hello @hemal
Just to explain what is happening…

you are getting this error because you are building datatable with external data i.e. an excel file. When UiPath read an excel file and build datatable… all the columns are assigned with datatype of ‘object’ (because UiPath does not know which column contains what type of data). Also every row item i.e cell will carry the datatype according to the value held by them (unless PreserveFormat in ReadRange>PreserviceFormat is checked, then they(all the row items) will have datatype of string)

to solve this issue you can use below query:
dt.select(“Convert([Col1],‘System.String’) = ‘60’ or Convert([Col1],‘System.String’) <> ‘S1’”)
or just check the PreserveFormat as suggested by @PrankurJoshi

~Akshay

2 Likes

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