我正在查询datagridview,除非其中一个单元格没有(dbnull),否则它很有用。怎么过来这个?
异常:没有为类型'DBNull'定义Operator'='并输入'DBNull'。
Dim query = From row As DataGridViewRow In DataGridView1.Rows _
Where row.Cells(SelectedColumnIndex).Value = filter _
And row.Visible = False _
Select row Distinct
答案 0 :(得分:2)
使用.Equals()
方法比较一个可能为null的值。例如:
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