1

I'm a little rusty on my VB.NET especially when converting to SQL. I thought I had a simple task of hiding 2 buttons unless a checkbox is checked. The checkbox is bound to a SQL Server column with a bit data type.

My code is as follows:

Private Sub CaseVehicleCollisionCheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CaseVehicleCollisionCheckBox1.CheckedChanged
    Dim collision As System.Data.SqlTypes.SqlBinary
    collision = CaseVehicleCollisionCheckBox1

    If collision = True Then
        btnVehicle1.Visible = True
        btnVehicle2.Visible = True
    ElseIf collision = False Then
        btnVehicle1.Visible = False
        btnVehicle2.Visible = False
    End If

End Sub

I keep getting the error

Value of type 'System.Windows.Forms.CheckBox' cannot be converted to 'System.Data.SqlTypes.SqlBinary'

when trying to assign the checkbox to the variable.

I get the same error when trying to use System.Data.SqlTypes.SqlBoolean

3
  • 2
    "The checkbox is bound to an SQL field " - huh? Commented Apr 15, 2013 at 4:18
  • @JeremyThompson - same results Commented Apr 15, 2013 at 4:28
  • Once you're using Boolean rather than SqlBinary, also note that there's no need for the If statement. Just say btnVehicle1.Visible = collision and btnVehicle2.Visible = collision. Commented Apr 15, 2013 at 7:23

2 Answers 2

2

The problem is you are casting a CheckBox control to a SQLBinary datatype and that isn't going to work.

I presume CaseVehicleCollisionCheckBox1 is the name of the CheckBox. You need to use the CheckBoxes Checked property, eg:

Dim collision As Boolean
collision = CaseVehicleCollisionCheckBox1.Checked
Sign up to request clarification or add additional context in comments.

1 Comment

@jstacy00 your welcome, there's a tickbox next to each answer, ticking it gives you a couple of points and saves people from spending time troubleshooting this by letting them know its working. Cheers!
0

Use SqlBoolean instead of sqlBinary. sqlBinary is the sql equivalent of an array of bytes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.