title: How to update table while looping the select command?
body: <pre><code>string connString = ConfigurationManager.ConnectionStrings["TestDatabase"].ConnectionString;
  SqlConnection conn = new SqlConnection(connString);
  try
  {
      conn.Open();
      string cmdUpdate = "UPDATE mem SET name =@name";
      string cmd = "SELECT * FROM mem;";
      SqlCommand comm = new SqlCommand(cmd, conn);
      SqlCommand commUpdate = new SqlCommand(cmdUpdate, conn);
      SqlDataReader dr = comm.ExecuteReader();
      while (dr.Read())
      {
          DateTime date = DateTime.ParseExact(dr["date"].ToString(), "dd-MM-yyyy", CultureInfo.InvariantCulture);
          if (date &lt; DateTime.UtcNow)
          {
              commUpdate.Parameters.Clear();
              commUpdate.Parameters.AddWithValue("@name", "Done");
              comm.ExecuteNonQuery();
          }
      }
      conn.Close();
  }
  catch (Exception ex) {
      MessageBox.Show(ex.ToString());
  }
  </code></pre>
  
  <p>This is my code.</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="TestDatabase" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Test.mdf;Integrated Security=True;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient"/&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>This is my connection string.</p>
  
  <p>I want to update the name while retrieve data and match the condition. Can anyone help me?</p>