Convert String To Int in DataTable

Hello,

I got this scenario. I have a data table with some columns type is the string I want to convert this column to an integer to do some calculation.

some posting that I’m already tried but still no luck :
https://forum.uipath.com/t/how-to-convert-string-to-int32-in-datatable/190501

https://forum.uipath.com/t/system-data-datatable-convert-to-string-or-integer/240620/2

Attach the sample process
ConvertToInt.zip (35.7 KB)

Thanks
Rangga

Hi

I would suggest to convert at the place where you want the value as int32
Just by mentioning as
Convert.ToInt32(your stringvariable) instead of mentioning directly your stringvariable

Cheers @rangga.waskita

Hi,

Thanks for the quick feedback, do you mean I have to do for each in DT and convert the value to int32?

Thanks

Yes. You will have to do it something like this.DtStringColumnToInt.xaml (8.2 KB)

Hi @ticsrobo.au @Palaniyappan

is there any other way to convert the data not using that method. The thing is the real data will have a thousands of rows I wonder is there any simple way that not loop to every rows in the DT.

Thanks,

For some reason, I am unable to extract your attached file ConvertToInt.zip Are you able to attached a new one?

Hi @ticsrobo.au ,

here’s the file

Thanks,

ConvertToInt.zip (35.7 KB)

Hi @rangga.waskita

Please try below steps,

Read the excel sheet data or use build datatable and store the data in the datatable variable name dt.

Drag and drop the invoke code activity.

In edit arguments, create a variable dt, set direction as in/out and pass value as dt.

In edit code type the following,

dt.asenumerable.tolist.foreach(sub(row) row(“Yourcolumnname”)= cint(row(“Yourcolumnname”)))

Write the datatable back into the excel using write range activity.

Or

We can use balareva activity to change the datatable column format, here is the reference for the same.

Hope this helps.

Thanks

1 Like

Hey, I think you’re solution is already correct. However, you missed the “add header” check box when reading the excel. Thus, you were actually reading Column H of the excel which are all zeros instead of Column G which has some non-zero values. I have attached the updated project.ConvertToInt.zip (10.5 KB)

Hi @prasath_S @ticsrobo.au

It’s works, :love_you_gesture:

thanks

1 Like

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