0
votes

When trying to Filter null value for integer type column leads to Evaluate exception(Cannot perform '=' operation on System.Int32 and System.String.). It's working for String type column. How to filter null value for integer type column in DataTable.

DataTable dt = new DataTable("MyTable");
DataColumn column = new DataColumn("Col", typeof(int));
column.AllowDBNull = true;
dt.Columns.Add(column);

for (int i = 0; i < 5; i++)
{
    DataRow row = dt.NewRow();
    row["Col"] = i;
    dt.Rows.Add(row);
}
dt.DefaultView.RowFilter = "Isnull(Col,'Null Column') = 'Null Column'";

Note: I want to use RowFilter. I don't want to use any other options.

1

1 Answers

2
votes

= would not work for checking NULL value. Use this RowFilter instead:

 dt.DefaultView.RowFilter = "Col IS NOT NULL";