Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 未为DBNull和Boolean类型定义运算符,但不存在运算符_Vb.net_Boolean_Operator Keyword_Infragistics_Dbnull - Fatal编程技术网

Vb.net 未为DBNull和Boolean类型定义运算符,但不存在运算符

Vb.net 未为DBNull和Boolean类型定义运算符,但不存在运算符,vb.net,boolean,operator-keyword,infragistics,dbnull,Vb.net,Boolean,Operator Keyword,Infragistics,Dbnull,在超级网格中检查复选框样式列的值时,我在BeforeRowsDeleted方法中使用以下代码来设置布尔值,然后根据布尔值运行两个删除方法中的一个 然而,我得到一个系统异常,说 未为DBNull和Boolean类型定义运算符 我以前见过这个错误好几次,但我很困惑,因为尽管在代码中我可以看到存储的值实际上是System.DBNull,但没有使用等号 为什么会发生此错误?代码哪里出错 If IsDBNull(ugProducts.ActiveRow.Cells("isNew").Value) Or _

在超级网格中检查复选框样式列的值时,我在BeforeRowsDeleted方法中使用以下代码来设置布尔值,然后根据布尔值运行两个删除方法中的一个

然而,我得到一个系统异常,说

未为DBNull和Boolean类型定义运算符

我以前见过这个错误好几次,但我很困惑,因为尽管在代码中我可以看到存储的值实际上是System.DBNull,但没有使用等号

为什么会发生此错误?代码哪里出错

If IsDBNull(ugProducts.ActiveRow.Cells("isNew").Value) Or _
            ugProducts.ActiveRow.Cells("isNew").Value = True Or _ 
            ugProducts.ActiveRow.Cells("isNew").Value = Nothing Then
        exProd = True
    Else
        exProd = False
    End If

我还尝试在网格的InitializeLayout方法中以编程方式设置值,但这并不能解决问题,问题在于您的条件

IsDBNull(ugProducts.ActiveRow.Cells(“isNew”).Value)
计算结果为
->True

然后你试着做:

ugProducts.ActiveRow.Cells(“isNew”).Value=True

如果值为
DBNull
,上述语句怎么可能为真?这就是代码失败的地方,因为
DBNull
,您试图将其与
True
进行比较(这就是
=
的位置)

如果条件为
DBNull
,则需要使用
OrElse
缩短条件:

If IsDBNull(ugProducts.ActiveRow.Cells("isNew").Value) OrElse _ 
如果它是
DBNull
,则它不会尝试进行其他比较,而是直接进入块