title: Updating data of selected row in datagridview
body: <p>I have datagridview with checkbox column and I want to update one value on a button click.Pending status=0 and Approved status=1. If I code</p>
  
  <pre><code>UPDATE pending SET status='1' WHERE status='0'
  </code></pre>
  
  <p>All status='0' will be '1' even the row without check. I want to update status to 1 only to the selected rows.  My codes are as follows: </p>
  
  <pre><code>private void btnApproved_Click(object sender, EventArgs e)
      {
  
  
          List&lt;DataGridViewRow&gt; selectedRows = (from row in gvPending.Rows.Cast&lt;DataGridViewRow&gt;() where Convert.ToBoolean(row.Cells["checkBoxColumn"].Value) == true select row).ToList();
          if (MessageBox.Show(string.Format("Do you want to approve these rows?"), "Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes)
          {
              foreach (DataGridViewRow row in selectedRows)
              {
                  using (var connect = sqlcon.getConnection())
                  {
                      using (SqlCommand cmd = new SqlCommand("UPDATE pending SET status='1' WHERE /* checkboxColumnValue is true */  "))
                      {
                          cmd.Connection = connect;
                          connect.Open();
                          //cmd.ExecuteNonQuery();
                          //connect.Close();
  
                      }
                  }
              }
              this.BindGrid();
              //this.BindGrid1();
              //this.BindGrid2();
          }
      }
  </code></pre>
  
  <p>Any suggestions or corrections? Thanks!</p>