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.

1 Like

@poogy112
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.

Regards,
Dominic :slight_smile:

5 Likes

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

@hojoong.kim
@Dominic,
@poogy112
Hi,

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 )

multipleImage2

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