DataTable Select function cannot perform “=” operation on System.Double and System.String

datatable
selector
uipath

#1

Hey! I have a datatable.select that’s returning the above error.

My select is this: “newDT.Select(”[Column4]="+"’{"+ProfitCenterRandom1+"}’").CopyToDataTable"

Do you have any idea of what this could be?


#2

Hello!

Are you trying to compare a String with a Double Variable?

Try this: “newDT.Select(”[Column4]="+"’{"+ProfitCenterRandom1.ToString()+"}’").CopyToDataTable"

Regards,


#3

Hey Lucas! No, I’m not, the ProfitCenterRandom is a string variable so it doesn’t need no parse. That’s what’s suspicius, i don’t know why im gettin g this error

@Lucas.Pimenta


#4

The error it’s because you’re trying to compare a string variable with a double variable. Maybe the [Column4] got double values. Try to parse it and see if works


#5

I did have the same error once when using a dynamic parameter in .SELECT. (here ProfitCenterRandom1)
It resulted from that parameter being empty upon passing.


#6

@Renato_Quintal @MarekMusial
use this code
newDT.Select(“Convert([Column4],‘System.String’)=’”+ProfitCenterRandom1+"’").CopyToDataTable()
Regards,
Arivu


#7

Hi @arivu96 ,
With ur solution, it returned error - Assign : Invalid type name ‘‘System.String’’.
Please help.


#8

Hi @crazywindy

Try This
newDT.Select("Column4='"+ProfitCenterRandom1.ToString+"'").CopyToDataTable()

Regards,
Arivu


#9

@crazywindy
Try this

(From p in newDT.Select()
where Convert.ToString(p.Item(“Column4”)).Equals(ProfitCenterRandom1.ToString)
select p).ToArray.CopyToDataTable

Regards,
Mahesh


#10

Hi @arivu96
I got the problem. ‘System.String’ should be used without single quote.


#11

Hi @crazywindy,
Remove the single quote and try again

newDT.Select(" "Convert([Column4],System.String)='"+ProfitCenterRandom1+"'").CopyToDataTable()

If suppose again you are facing the problem pls send the xaml file.

Regards,
Arivu


#12

Hey @crazywindy

Check this:-
IF your Column Datatype is Int, Double kinda then use below like code.

dt.Select("Convert([Col Name],‘System.String’) = " + Your_variable_name.ToString())

and if your Column Datatype is of String then use below code.

Datatable result = dt.Select(“Convert([Col Name],‘System.String’) = ’ " + salary.ToString()+” ’ ").CopyToDatatable()

where-

dt - your datatable Name
Col Name - Datatable Column Name

Regards…!!
Aksh


#13

Thanks @aksh1yadav now it is working without single quote.


#14

Thanks @arivu96 now its working.


#15

thank you very good it work very well for me.

:smile:


#16

@aksh1yadav In my datatable column is string type now I want to covert that string type to double and check with another double value whether it is equal or not.by using select function