Convert selected columns in a datatable into integer using linq

Hello Everyone,

Need help with a quick linq query to convert selected string columns into interger type and store in a datatable variable

Hi @krishna_r

Please try this:

Assign activity:

datatableOutput = (From row In datatableInput.AsEnumerable()
Select datatableInput.Clone().Rows.Add(row.ItemArray.Select(Function (x) If(IsNumeric(x.ToString.Trim),Convert.ToInt32(x.ToString.Trim),x)).ToArray())).CopyToDataTable()

Hope this helps,
Best Regards.

error message: is numeric is not declared

A column defining a datatype of String cannot be populated with an int32

page unavailable.
Can you please elaborate

1 Like

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