title: Inserting value from Checkbox Template Field into sql database field type Bit
body: <p>I have a gridview which has a Checkbox Template Field, I am using C# code and basically when the user checks all the Checkboxs in the datagrid view I want to add these values into an SQL database with a datatype field Bit.
  Here is my code so far;</p>
  
  <pre><code>protected void SaveRegisterButton_Click(object sender, EventArgs e)
  {
              SqlConnection connection;
              SqlCommand command;
              int numRowsAdded;
              int id;
              Boolean AttendanceChecked;
      foreach (GridViewRow row in GridView2.Rows)
      {
          if (((CheckBox)row.FindControl("AttendanceCheckBox")).Checked)
          {
  
  
              try
              {
                  // Connecting to the database using the connection string in the web.config file
                  connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["RegisterConnectionString"].ConnectionString);
  
                  // Create an INSERT Sql statement
                  // To prevent an Sql injection attack, we add parameters with names starting with an @ symbol
                  command = new SqlCommand("INSERT INTO Attendance(Present, StudentID, LessonID) VALUES(@AttendanceChecked, @StudentID, @LessonID)",
  
  
                  // Replace the parameters with the actual values read from the form
                  //command.Parameters.AddWithValue("AttendanceChecked", AttendanceCheckBox);
  </code></pre>
  
  <p>How do I pass the value of the checkbox control into the sql database field with data type Bit? Any help is appreciated, thanks in advance!</p>