Using the Select Method gives me this error: Cannot perform '=' operation on System.Double and System.String

Hi there, I’m relatively new to UiPath. I have some excel files in which I’m trying to use the Select method to store the data of the Subtotal, GST, and Total into respective variables. Please see below a sample of the excel file:-
image

Using the Assign activity, I tried using the Select method in extracting the Subtotal, GST, and Total from the table using the following:-
Subtotal = tableDT.Select(“PRICE = 'Sub Total '”)(0)(“TOTAL”).ToString
GST = tableDT.Select(“PRICE = 'GST 8% '”)(0)(“TOTAL”).ToString
Total = tableDT.Select(“PRICE = 'Total '”)(0)(“TOTAL”).ToString

However, I was met with this error:-

May I know how I can resolve this?

Thank you!

@schee013 The error might be due to the data type of the column being different than a String type as you are trying to Match a String value in that Column. You can maybe convert the The Column Value to String and then match it with a String Value and check if it works, a similar conversion is given in the post below :

Can you check this post :

2 Likes

@schee013
give a try on forcing the conversion like:
Subtotal = tableDT.Select(“Convert(PRICE, ‘System.String’) = 'Sub Total '”)(0)(“TOTAL”).ToString

An alternate Approach would be LINQ
(From d in tableDT.AsEnumerable
Where d(“PRICE”).ToString.Trim.Equals(“Sub Total”)
Select s = d(“TOTAL”).ToString).Single()

the Single() method throws an exception in case of not 1 only value is retrieved. So it can be used for result checking

2 Likes

This worked! Thank you so much :slight_smile:

@schee013
Perfect, it is working. Was it solved with the Convert function or with the LINQ statement?

Using the convert function, but without the single quotes for System.String. :smiley:

@schee013
thanks for feedback. May I ask you to set the solution flag to @supermanPunch as he initial gave the hint for a solution.

2 Likes

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