How do I change all rows in my datatable to data type: String

It seems that my data table have some "double’ (I guess it is because I have rows like: 4,14 etc.) data type inside. I need all my data table to be all string

How do I do that? my data table name is: data_table

I need all that is inside this data table to be string and not double

Oh I need this to be data table but data inside to be string I’m not sure if this is clear

Hi @marcin.chowaniec

Try this

// Assuming you have a DataTable named data_table
// Create a new DataTable to store the result
DataTable stringDataTable = New DataTable();

// Clone the structure of the original DataTable
stringDataTable = data_table.Clone()

// Use LINQ to copy the data while converting all values to strings
stringDataTable = (From row In data_table.AsEnumerable()
                   Select stringDataTable.Rows.Add(row.ItemArray.Select(Function(field) field.ToString()).ToArray())).CopyToDataTable()

// Now, the stringDataTable contains all values as strings

If you are using the Generate Data Table Wizard in StudioX, I would uncheck the “AutoDetect Column Types” option.

No i dont use it i read data table from excel,


Try like this (37.6 KB)

Hope you understand!!

Thank you however I use Studio X and cannot open the file. Could you please copy the code from the second Assign here?


(From row In DT.AsEnumerable()
                   Select StringDataTable.Rows.Add(row.ItemArray.Select(Function(field) field.ToString()).ToArray())).CopyToDataTable()

DT is my data table the original incorrect one right?

Yes @marcin.chowaniec

DT is your input data table

I get error: input array is longer than the number of col in this table

Can you please provide some sample excel file @marcin.chowaniec

1 Like

I foumd the solution I used for each row in column and then row.ToString

Thanks anywayt <3

No need to run for each if there is huge data it takes time, please try this

By using Invoke Code activity @marcin.chowaniec


    ' Iterate through each row and convert values to strings
    For Each row As DataRow In dataTable.Rows
        For Each column As DataColumn In dataTable.Columns
            row(column.ColumnName) = row(column.ColumnName).ToString()

Thanks but I’m done. I’m too tired for this For each is enough I don’t have that many rows