Filter DataTable with multiple conditions

So far all the guide and post I see online only has a single condition like dt.Select("[ColumnX]=‘Test’"). Is there a way to filter out the dataTable with 2 conditions, for example, dt.Select("[ColumnX]<>‘Test’") and dt.Select("[ColumnX]<>‘Sample’"). I have tried it out personally and I can’t seem to get it working.

Try this:
dt.Select("[ColumnX]<>‘Test’ and [ColumnX]<>‘Sample’")

1 Like

@poogy112, To make it more simpler use this dt.Select("[ColumnX] Not in (‘Test’,‘Sample’)"). You can add multiple conditions here.

Dominic :slight_smile:


Concise and better syntax than my suggestion, thanks!:grinning:

I need to filter the Data table with multiple filter values/arguments ,

I tried below syntax, but getting error .Please let me know any one.

I’m uploading some images for references(Actually I need to filter more than 5 values )


use ‘or’ instead of ‘and’ in your query… like below
(from row in dt.Select() Where(row(“name”).ToString.Equals(“Siva”) or row(“name”).ToString.Equals(“Sai”) ) Select row).Count.ToString

your query failed because no row in column ‘name’ can be “Siva” and “Sai” at the same time

If there are more than 3 values for condition, I will suggest go for array check like below:
(from row in dt.Select() Where({“A”,“B”,“C”}.contains(row(“name”).tostring)) Select row)

1 Like