Invalid cast

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a check box on a Web form that I have named “chkBackedUpâ€. When I run
the application, I receive the following error:

Exception Details: System.InvalidCastException: Invalid cast from
System.Boolean to System.Byte[].

The code which defines the parameter and assigns the value of the check box
to the parameter in the application is:

Dim prmBackedUp As New SqlParameter("@BackedUp", SqlDbType.Binary)
cmdInsert.Parameters.Add(prmBackedUp)

prmBackedUp.Value = chkBackedUp.Checked

How can I get around this error?
 
Since you are trying to store a boolean value, you should use
SqlDbType.Bit instead of .Binary.

SqlDbType.Binary expects a byte array.
 
Back
Top