How to filter datatable based on range?

Hi guys,

I am having problem to filter data table based on 2 values.

For example, i am trying to filter a data table with values between 89.9 to 110.

I already trying to use filter data table activity but it returns no row.

Anyone have any idea to solve this one?

Hi,

If there is only numeric data in the target column, the following will work.

filteredDt = dt.AsEnumerable.Where(Function(r) Double.Parse(r("Columnname").ToString)>89.9 AndAlso Double.Parse(r("Columnname").ToString)<110).CopyToDataTable()

If there is non-numeric data including blank, we need to modify the above expression.

Regards,

Thanks man for the reply.

I receive this error:

The source contains no data rows.

Any thought to fix this error?

Hi,

The source contains no data rows.

This mean there is no row which matches the condition.
To avoid this error, can you try as the following?

arrayDataRow =  dt.AsEnumerable.Where(Function(r) Double.Parse(r("Columnname").ToString)>89.9 AndAlso Double.Parse(r("Columnname").ToString)<110).ToArray()

Hope this helps you.

Regards,

Thanks bro.

It works like a charm.

Have a nice day. :kissing:

1 Like

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