Unable to cast object of type 'System.Double' to type 'System.String' Help

I am trying to assign the result of the below query using the Assign activity and it is giving me the error.
I am assigning the value to a DataTable variable.

Query: InterswitchMerged_DT_SheetWithCountMO2.AsEnumerable().GroupBy(Function(i) i.Field(Of String)(“Merchant_Account_Nr”)).Where(Function(g) g.Count() >= 1).Select(Function(g) g.First).CopyToDataTable
Error: Unable to cast object of type ‘System.Double’ to type ‘System.String’.

2 Likes

Please note that I am using this expression before now and it is working fine.

Hi @Bukola

Welcome to our UiPath Forum! :slight_smile:

Could it be that you are running this query on a different DataTable than originally?

DataTable stores values according to a certain data type per column. You can check the data type of your column with the .GetType.ToString method on that column.

If I were to guess, you should explicitly cast your String value to a Double before performing comparisons on it.

@Bukola If you’re Still facing problems with that Query, Try replacing i.Field(Of String)(“Merchant_Account_Nr”) with i(“Merchant_Account_Nr”).ToString and check if it works.

5 Likes

My bad, you’re right → it fails at conversion to String :sweat_smile:

@loginerror I guess another method would be your way to use (Of Double) instead (Of String) :smile: But normally we wouldn’t know the Datatypes of each column and hence converting an Object to String is the method i follow :sweat_smile:

1 Like