How to filter a datatable using both AND and OR condition in Select method?

Hi All

How to filter a datatable using both AND and OR condition in Select method ?

OR condition for a single column and AND condition for a different column.

Kindly help with an example.

AND condition implemented for Product column
OR condition implemented for Country column

When you run the below query you will get 2 rows in output

input_dt.Select(“[Product] = ‘Chai’ and ([Country] = ‘India’ OR [Country] = ‘Great Britain’)”).CopyToDataTable

When you run the below query you will get 3 rows in output

input_dt.Select(“[Product] = ‘Chai’ and ([Country] = ‘India’ OR [Country] = ‘Great Britain’ OR [Country] = ‘Brazil’)”).CopyToDataTable

Note: Enclose the OR condition inside brackets

1 Like

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