RowFilter with IN operator over a column of type Guid
Apply a RowFilter on a DataView which filters a column of type System.Guid and can contain a variable number of values.
DataView dv = new DataView();
dv.RowFilter = \”TypeId in (\’\’, \’\’, …)\”;
where TypeId column is of a System.Guid type. As the number of values is variable it makes perfect sense to use the in operator.
When you are looking at this expression you may think this should be working as expected, i.e. the result should only contain the data where TypeId is in the specified values. In fact, if you run it you will get the following exception:
Cannot perform \’=\’ operation on System.Guid and System.String.
To convert the String to Guid you should use the Convert(expression, type) method like this:
dv.RowFilter = \”TypeId in (Convert(\’\’, \’System.Guid\’), Convert(\’\’, \’System.Guid\’),