vb.net 运算符 '=' 未为类型 'DBNull' 和类型 'Boolean' 定义。??/

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26051801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:16:38  来源:igfitidea点击:

Operator '=' is not defined for type 'DBNull' and type 'Boolean'.??/

vb.netnull

提问by Ashley Smith

I am going to count the checked and unchecked check box in my attendance but that come out in my code."Operator '=' is not defined for type 'DBNull' and type 'Boolean'.??"... pls help..your help is greatly appreciated. thanks

我将计算出勤中选中和未选中的复选框,但这会出现在我的代码中。“运算符 '=' 未为类型 'DBNull' 和类型 'Boolean' 定义。??”...请帮忙。非常感谢您的帮助。谢谢

my code:

我的代码:

Next

下一个

    Dim Present As Integer = 0
    Dim Absent As Integer = 0
    For a = 0 To Table2___lieDataGridView.RowCount - 1
        For b = 0 To Table2___lieDataGridView.ColumnCount - 8
            If Table2___lieDataGridView.Rows(a).Cells(b + 5).Value = True Then

                Present += 1
            Else
                Absent += 1
            End If
        Next
        Table2___lieDataGridView.Rows(a).Cells(10).Value = Present
        Table2___lieDataGridView.Rows(a).Cells(11).Value = Absent
        Present = 0
        Absent = 0


    Next

回答by Alex Wiese

You need to use the IsDBNullfunction to check for a null value before making the comparison.

在进行比较之前,您需要使用IsDBNull函数来检查空值。

If Not IsDBNull(Table2___lieDataGridView.Rows(a).Cells(b + 5).Value) AndAlso Table2___lieDataGridView.Rows(a).Cells(b + 5).Value Then
End If

回答by user3782235

Before you compare the Value to True, you should check if the Value is NOT actually DBNull type. It is because you happen to have null values in your database, and there is no comparative operator against boolean for that situation.

在将 Value 与 True 进行比较之前,您应该检查 Value 是否实际上不是 DBNull 类型。这是因为您的数据库中碰巧有空值,并且在这种情况下没有针对布尔值的比较运算符。

For example, look this question: Handling DBNull data in VB.Net

例如,看这个问题:在 VB.Net 中处理 DBNull 数据