title: How to update selected row in Gridview?
body: <p>I have a TextBox with id=txtPlace and a gridview. If a user selects a row an put some Information in the TextBox and click on save. The Information should replace older records in the database(SQL)</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code> protected void btnSave_Click(object sender, EventArgs e)
      {
          var id = GridView2.SelectedDataKey.Values[0].ToString();
          string constr = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
          using (SqlConnection conn = new SqlConnection(constr))
          {
  
              string query = "UPDATE user SET place= @place where ID = @ID ";
              SqlCommand cmd = new SqlCommand(query, conn);
              cmd.Parameters.AddWithValue("@place", txtPlace.Text);
              cmd.Parameters.AddWithValue("@ID", id);
  
          }
      }</code></pre>
  </div>
  </div>
  </p>
  
  <p>But It does not work. When I click on save, nothing happens.</p>