title: Multiple Updates in Check Box of Data Grid View
body: <p>I am trying to update the status of Column based on the Checkbox Column 'Status'.
  I am right not able to update only one row at a time. I need multiple updates to happen at the same time.</p>
  
  <p><a href="https://i.stack.imgur.com/f1InZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f1InZ.png" alt="enter image description here"></a></p>
  
  <p>Below is my piece of code:</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
      foreach (DataGridViewRow row in dataGridView2.Rows)
      {
          if (con.State == ConnectionState.Open)
          {
              con.Close();
          }
          if (row.Cells["txtStatus"].Value != null)
          {
              if (Convert.ToBoolean(row.Cells["txtStatus"].Value) == true)
              {
                  con.Open();
                  string query = @"update tbl_Training_Records_CIP_dotnet set Attendance_Status = 'Attended' where RequestId=@RequestId";
                  SqlCommand cmd = new SqlCommand(query, con);
                 // cmd.Parameters.AddWithValue("@training_id", row.Cells["txt_Training_ID"].Value.ToString());
                  cmd.Parameters.AddWithValue("@RequestId", row.Cells["txtRequestId"].Value.ToString());
                  cmd.ExecuteNonQuery();
                  MessageBox.Show("Records have been updated");
                  con.Close();
                  loaddatatable2();
              }
          }
  </code></pre>