1
votes

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

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
2
You need to check if value is Nothing or DBNull and if it is not then you can safely cast it to a Boolean and then make the comparison.Alex Wiese
thank you for your comment.. where would i check it?Ashley Smith
See my answer below. You can use the built-in IsDBNull functionAlex Wiese

2 Answers

1
votes

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

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

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.

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