title: SqlDateTime overflow when using .ExecuteReader
body: <p>I am getting this error when executing a reader which is used on an asp page:</p>
  
  <blockquote>
    <p>SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.</p>
  </blockquote>
  
  <p>A date is selected from a calendar, and is set to a <code>DateTime</code> variable, which is then used as a parameter in an SQL command. It seems to randomly work, I select a date once and it works, I reload the page and select the same day and it might not work.</p>
  
  <p>My relative code is below, I'm getting the error at the <code>.ExecuteReader()</code> line.
  I've checked the <code>confirmedDate</code> variable right before the reader is executed, and it does have a valid <code>DateTime</code>.</p>
  
  <pre><code>    DateTime confirmedDate = DateTime.Parse(dateSelected);
      SqlCommand command4 = new SqlCommand();
      command4.Connection = gconn;
      String sql4 = "SELECT MAX([Day]) as TheDay FROM Days WHERE User_ID = @User_ID AND [Day] &lt; @dateSelected AND NOT EXISTS (SELECT 1 FROM Days WHERE User_ID = @User_ID AND [DAY] &gt;= @dateSelected)";
      command4.CommandText = sql4;
      command4.Parameters.Add(new SqlParameter("@User_ID", ""));
      command4.Parameters.Add(new SqlParameter("@dateSelected", confirmedDate));
  
  
  for (int i = 0; i &lt; firstName.Count; i++ )
  {
      command4.Parameters["@User_ID"].Value = userID[i];
  
      using (SqlDataReader reader = command4.ExecuteReader()) //error here
      {
          while (reader.Read())
          {
              if (reader.HasRows)
              {
                  if (reader["TheDay"].ToString() == "") 
                  {
                      dates.Add("NULL"); 
                  }
                  else
                  {
                      dates.Add(reader["TheDay"].ToString());
                  }
              }
          }
      }
  }   
  </code></pre>
  
  <p>I've looked up other questions regarding this but can't find a solution that works. A valid <code>DateTime</code> value is always being passed in.</p>