Link to home
Start Free TrialLog in
Avatar of dswett2
dswett2

asked on

Sending a checkbox value to a stored procedure

I have a few bit columns in a table in a database. I have a stored procedure in which I pass values to create a record. I represent these bit values as checkboxes on my .aspx page. I'm looking to pass the state of these checkboxes (checked = 1, unchecked = 2) to my storedprocedure.

My existing vb code is below which is passing String values fine. I just need the syntax for the lines: ******DIM checkboxes (cb1, cb2, etc)************ and *******Add cb1, cb2 paremeters******
Dim connectionstring As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        Dim ObjConn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionstring)
        Dim objCmd As SqlCommand = New SqlCommand()
        objCmd.Connection = ObjConn
        Dim codereference As String = txtCodeReference.Text
        Dim description As String = txtDescription.Text
        Dim category As String = txtCategory.Text
 
******DIM checkboxes (cb1, cb2, etc)************
 
        objCmd.CommandType = System.Data.CommandType.StoredProcedure
        objCmd.CommandText = "dbo.AddInspectionToPicklist"
        objCmd.Parameters.Add("@codereference", Data.SqlDbType.VarChar).Value = codereference
        objCmd.Parameters.Add("@description", Data.SqlDbType.VarChar).Value = description
        objCmd.Parameters.Add("@category", Data.SqlDbType.VarChar).Value = category
 
*******Add cb1, cb2 paremeters******
 
        ObjConn.Open()
        objCmd.ExecuteNonQuery()
        ObjConn.Close()

Open in new window

Avatar of naspinski
naspinski
Flag of United States of America image

Keep in mind that bits are stored as 1 or 0, not 1 or 2, so you will want to address that by either changing the values to 1 and 0 or transforming the variables before insert.

Otherwise, you would just add it like any other parameter.
objCmd.Parameters.Add("@checkBox", Data.SqlDbType.Bit) = chkBox.Checked

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of prairiedog
prairiedog
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A typo in the second If/EndIF block:

If (myCheckBox2.Checked = True) then
   cb2 = 1    <==== Not cb12 = 1
Else
   cb2 = 2
End If
Avatar of dswett2
dswett2

ASKER

perfect, thanks!