Datable Column as string. Need as Integer


Hoping someone can help me with this please?

I have the following datatable - Search Results DT.

This has pulled through where all columns are string. I need column “Days_Open__c” to be an integer so I can use the filter datatable activity.

I can’t seem to make sense of anything I have read in the forum for this issue but it has been asked a few times.

Does someone have a quick fix that will mean I don’t have to create a new datatable?

1 Like

Hello @Em126351

You can go through this post,

Cint(row(“YourColNameOrIndex”).toString) is pulling out the value as Integer
using it for filtering can be done with the datatable.Select( … method or with LINQ

@Pradeep_Shiv this is for excel so no use. I’m using a datatable.

@ppr you’re approach seems more like what I’m looking for, however I’m not that experienced. I have no idea about LINQ… Can you dumb that down any more?

@Em126351 Maybe this is what you’re looking for :

I would suggest to start with the select method, could be easier to start with:

here the part Convert Function like: “Convert(total, ‘System.Int32’) = 2”

In Linq it would look like:

(From d In YourDataTableVar.AsEnumerable
Where CInt(d(YourColNameOrIndex).toString.Trim) = 5
Select d).CopyToDataTable

with the assumption that the filter result is not empty otherwise CopyToDataTable throws an exception. If there is a risk of empty result then it can be handled as here:

@ppr thanks for sending that over. I’ll be honest I haven’t used it. But its definitely helped me make more sense of it. In the end I have just added a new int32 data column, then in a for each row, taken the value from the string column, converted in to int and added into the int32 column. I’ll just tidy it up and remove the string column. Not ideal for big datatables I guess but I’m only expected a few lines of data.

1 Like

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