Datatable select with multiple conditions

前端 未结 7 1976
再見小時候
再見小時候 2020-12-02 17:03

I have a datatable with 4 columns A, B, C and D such that a particular combination of values for column A, B and C is unique in the datatable.

Objective:

7条回答
  •  不思量自难忘°
    2020-12-02 17:18

    I found that having too many and's would return incorrect results (for .NET 1.1 anyway)

    DataRow[] results = table.Select("A = 'foo' AND B = 'bar' AND C = 'baz' and D ='fred' and E = 'marg'"); 
    

    In my case A was the 12th field in a table and the select was effectively ignoring it.

    However if I did

    DataRow[] results = table.Select("A = 'foo' AND (B = 'bar' AND C = 'baz' and D ='fred' and E = 'marg')"); 
    

    The filter worked correctly!

提交回复
热议问题