Search code examples
c#winformsdatatablerowfilter

Correct syntax for RowFilter


I can't find anything about this kind of syntax around the internet. I'm using following syntax to search in a DataTable:

dtSearch.DefaultView.RowFilter = 
"(Id = '426124' OR Id = '426155' OR Id = '426186') AND 
 (Name, Surname = 'xyz, abc' OR Name, Surname = 'uvw, def')"

Here I'm getting a systax error. What's wrong here? How to construct a statement which is based on multiple OR and AND parts the one above?

I tried to leave out brackets and use '' on the column names but nothing seems to work here.

Thank you!


Solution

  • If i understand correctly "Name,Surname" is a column name with space.
    You must use square brackets if column name has space in it,

    ([Name, Surname] = 'xyz, abc' OR [Name, Surname] = 'uvw, def')"
    

    Please refer to similar question
    How to filter datagridview across field name which has space character?