title: schedule for update date in asp.net
body: <p>I want to make schedule that run after every 24 hours in asp.net (global.asax). 
  I just want to check current date and date which are store into my database one by one. if date is less than current date then add 7 days into it.</p>
  
  <p>I am just trying but without close the reader update is not possible. this kind of error shows me every time.</p>
  
  <pre><code>private static void Task()
  {
      String CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
      using (SqlConnection con = new SqlConnection(CS))
      {
          con.Open();
          DateTime Newdate;
          String ct = DateTime.Now.ToString("dd/MM/yyyy");
          DateTime CT = DateTime.ParseExact(ct, "dd/MM/yyyy", CultureInfo.InvariantCulture);
          SqlCommand cmd1 = new SqlCommand("select Date from tblInsertDate", con);
          cmd1.ExecuteNonQuery();
          SqlDataReader rdr = cmd1.ExecuteReader();
          while (rdr.Read())
          {
              DateTime dt = DateTime.ParseExact(rdr["Date"].ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
              int result = DateTime.Compare(dt, CT);
              if (result &lt; 0)
              {
                  Newdate = dt.AddDays(7);
                  SqlCommand cmd2 = new SqlCommand("update tblInsertDate set Date=@Newdate", con);
                  cmd2.Parameters.AddWithValue("@Newdate", Newdate);
                  cmd2.ExecuteNonQuery();
              }
          }
      }
  }
  </code></pre>
  
  <p>I make the schedule in global.asax with the help of timer. </p>