Error in Convert String into int32/Double/Int64

Hello,

Hope you all are doing well.

I came across a problem where I need to convert a string values(Amount) to integer values. I have 2000 records and I am getting error “Add Data Row: Conversion from string “” to type ‘Integer’ is not valid” on 331st record. All previous records are getting converted just fine.

I am Building a datatable with Amount Column of int32 datatype and adding data row from other data table inside for each row where ArraryRow value is cint(row(“Amount”).tostring. Below are sample amount data. I am getting error on 110,473.11 value. Please help.
25,370.00
2,000.00
28,200.00-
1,000.00
1,718.00
900
1,500.00
1,895.00
1,895.00
1,843.30
59,846.16
2,500.00
2,500.00
2,940.00
110,473.11
9,250.00
3,026.97
150
571.49
818.86
9,170.00
2,475.20

an empty string cannot be converted into an int / double …
give a try on make it defensive with following:
e.g. cint(“0” & row(“Amount”).tostring)
grafik

But kindly note: 110,473.11 has a decimal part
grafik

And also:
grafik
grafik

Screenshots done within UiPath during debugging (step wise or paused on breakpoint) on the immediate panel

None of the string is empty in my case. and as I mentioned all the records are getting converted until 331st record with cint(row(“Amount”).tostring. there are value before 110,473.11 which has
decimal and converted just fine.

Exception is stating this
Conversion from string “” to type ‘Integer’ is not valid”

And also replicated:
grafik
grafik
grafik

Working fine with:
grafik
sometimes we can also use an additional Trim()
grafik

In case of larger datasets we can write a small LINQ filtering out values that are not convertable and do an analysis on the result. Often we can do it directly in the immediate panel e.g.:

1 Like

Error clearly states that the cell value is empty and that is the reason it is failing. Could you please share the data(just with that column) with all the records with us??

1 Like

Hi Prasath,

I see some empty cells but not on the row where error occurred.

In build data table activity, I have 3 columns which is updated in Add Data row activity inside a for each activity.
Column A is string, Column B is string and Column C(Amount) is Int32

Are you sure? If the error not occurred on the empty cell , error message would have clearly showed the cell value. Please post the debug screenshot.

here are few screenshots
Error:
image

Datatable where execution failed - Row 332
image

Activity where error occurred
image

Exception detail:

Add Datarow expression
image

Excel values at 332nd record
image

local value panel is triming / cut off after a certain amount of data (… Indicator). So the problem record can also be located on later records. Thats why we do run the LINQ analysis statements. Another technique is to work with conditional breakpoints / tracepoints for reacting on certain values / situations. As shown in the screenshots from above the 110,473.11 value is parseable.

can you provide a sample on how should I proceed from here?

Is it a CSV file? If yes, try to open it in notepad and look for two consecutive commas(,)