Invalid cast

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?
 
C

Chris Dunaway

Since you are trying to store a boolean value, you should use
SqlDbType.Bit instead of .Binary.

SqlDbType.Binary expects a byte array.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top