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

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?

Hello!

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

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

Regards,

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

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

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.

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

1 Like

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

Hi @crazywindy

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

Regards,
Arivu

@crazywindy
Try this

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

Regards,
Mahesh

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

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

1 Like

Hey @crazywindy

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

dt.Select("Convert([Col Name],‘System.Int32’) = " + 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

16 Likes

Thanks @aksh1yadav now it is working without single quote.

Thanks @arivu96 now its working.

thank you very good it work very well for me.

:smile:

@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

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