Reputation: 85
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
Upvotes: 1
Views: 4779
Reputation: 1180
Use SqlBoolean instead of sqlBinary. sqlBinary is the sql equivalent of an array of bytes.
Upvotes: 0
Reputation: 65544
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
Upvotes: 2