1

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
3
  • 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. Commented Sep 26, 2014 at 4:01
  • thank you for your comment.. where would i check it? Commented Sep 26, 2014 at 4:04
  • See my answer below. You can use the built-in IsDBNull function Commented Sep 26, 2014 at 4:07

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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

4 Comments

i suppose to both u up but need atleast 15reputation
I have another question? do you know what is the reason why when i add querry on datagridview does not have txtbox? i wanted to do search but no txtbox in my query? only fillby button...pls help
@AshleySmith you should ask another separate question and make sure you post some code so we can be clear on what you want. I'm having trouble understanding your question.
1st.in the datagridview arrrow i click 2. i fill in fillbyIDnumber 3. i click the query builder then under filter i fill the row ID Number "LIKE@IDNumber + '%' "..then when i press okay.. fill by does not have txtbox only fillby button

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.