The DataTable.Select() function returns the wrong rows with a filter like this...
"booleanColumn1 AND booleanColumn2 AND GuidColumn1 = '00000000-0000-0000-0000-000000000000')"
Making virtually any alteration to this format fixes it (see example). Using the same filter on a dataView works correctly. I'm tempted to change it to
"booleanColumn1 = 1 AND booleanColumn2 = 1 AND GuidColumn1 = '00000000-0000-0000-0000-000000000000')"
and declare it fixed (the documentation makes no mention of whether "A" or "A = 1" is the correct syntax for boolean columns). But the blame could just as easily be placed on the Guid column. Before I revisit the hundreds of places we use DataTable.Select() in our codebase, I was hoping to see if anyone knew what was really going on.
DataTable dt = new DataTable("dt");
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("ID", typeof(Guid)),
new DataColumn("A", typeof(bool)),
new DataColumn("B", typeof(bool))
});
dt.Rows.Add(Guid.Empty, false, true);
// this incorrectly returns a row
Debug.WriteLine(dt.Select("B AND A AND ID = '00000000-0000-0000-0000-000000000000'").Length);
// yet it's fine for a DataView (correctly returns 0 rows)
DataView dv = new DataView(dt);
dv.RowFilter = "B AND A AND ID = '00000000-0000-0000-0000-000000000000'";
Debug.WriteLine(dv.Count);
// these correctly return 0 rows
Debug.WriteLine(dt.Select("B AND A").Length);
Debug.WriteLine(dt.Select("B AND A AND CONVERT(ID, 'System.String') = '00000000-0000-0000-0000-000000000000'").Length);
Debug.WriteLine(dt.Select("A AND B AND ID = '00000000-0000-0000-0000-000000000000'").Length);
Debug.WriteLine(dt.Select("B = 1 AND A AND ID = '00000000-0000-0000-0000-000000000000'").Length);
Debug.WriteLine(dt.Select("ID = '00000000-0000-0000-0000-000000000000' AND B AND A").Length);
Debug.WriteLine(dt.Select("B AND (A AND ID = '00000000-0000-0000-0000-000000000000')").Length);
// still wrong
Debug.WriteLine(dt.Select("B AND A AND ID = '00000000-0000-0000-0000-000000000000'").Length);