locked
How to save checkbox values into sql server 2005 via c#

    Question

  • Hi there

    I want to know how I can save a checkbox value into sql server 2005?  The check box is in my windows forms application...

    Thanks
    Thursday, November 25, 2010 6:48 AM

All replies

  • Try following code

        Dim query As String = "INSERT INTO TABLENAME (CheckBoxColumn) VALUES (@CheckBoxColumn)"
        Dim conn As New SqlClient.SqlConnection("Connection String")
        Dim cmd As New SqlClient.SqlCommand(query, conn)
        If CheckBox1.Checked = True Then
          cmd.Parameters.Add("@CheckBoxColumn", SqlDbType.Bit).Value = 1
        Else
          cmd.Parameters.Add("@CheckBoxColumn", SqlDbType.Bit).Value = 0
        End If
    
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
    

    You can get connection string from http://www.connectionstrings.com.


    Gaurav Khanna
    Friday, November 26, 2010 6:18 PM