我正在查询一个datagridview,它工作得很好,除非其中一个单元格没有任何东西(dbnull)。如何克服这一点?
异常:对于类型'DBNull'和'DBNull'没有定义运算符'='。
Dim query = From row As DataGridViewRow In DataGridView1.Rows _
Where row.Cells(SelectedColumnIndex).Value = filter _
And row.Visible = False _
Select row Distinct
使用.Equals()
方法比较可能为空的值。例子:
Dim query = From row As DataGridViewRow In DataGridView1.Rows _
Where row.Cells(SelectedColumnIndex).Value.Equals(filter) _
And !(row.Visible) _
Select row Distinct
或者如果两者都为null,您可以使用基本Object.Equals()
方法进行比较:
Dim query = From row As DataGridViewRow In DataGridView1.Rows _
Where Object.Equals(row.Cells(SelectedColumnIndex).Value, filter) _
And !(row.Visible) _
Select row Distinct