How to convert String to int?

I have data table as below.

image

But I want filter column APADT by use filter dataTable > 25650101

But after filter —> It show blank data.

Please guide me for solve it.

Hi @fairymemay

If it is an date, then you can use the follow snippet of code →

Dt.AsEnumerable().Where(Function(w) DateTime.ParseExact(w("APAPDT").ToString.Trim,"yyyyMMdd",Nothing) > [DateToCompareWith] ).CopyToDataTable()

But if its a integer, then you can use the following snippet of code →

 Dt.AsEnumerable().Where(Function(w) CInt(w("APAPDT")) > [ValueToCompareWith]).CopyToDataTable

Kind Regards,
Ashwin A.K

@fairymemay You can convert string data to int using following command.

out_intvalue = Cint(in_str)

The output will in integer data type.

@fairymemay

Here column name should be APAPDT but not APADT. you can try below Linq query.

        dtOutput = dtInput.AsEnumerable.Where(Function(row) Cint(row("APAPDT").ToString) > 25650101).CopyToDataTable
1 Like

refer to my sequence
test.xaml (15.6 KB)

you can create a new datatable and add integer columns then clone the old datatable over

Example datatable (dt)
image

steps

  1. initialize new datatable dtNew
    image

  2. loop over dt.Columns, for each column add new column (type integer) to dtNew
    image

  3. loop over dt rows, for each row create add the corresponding values (converted to integer) to a new row in dtNew
    image

  4. now dtNew is the same as dt, but converted to integer

@ashwin.ashok If I have file config for keep date for filter as below.

If filter column APADT (for filter from column Start_APAPDT and End_APAPDT) and filter APDODT (for filter Start_APDODT and End_APDODT)

  • Sometime file config have 1 row or more than 1 rows.
    config2.xlsx (8.9 KB)

How to edit your code?

 Dt.AsEnumerable().Where(Function(w) CInt(w("APAPDT")) > [ValueToCompareWith]).CopyToDataTable

Please guide me about it.