title: get wrong date for my databind method
body: <p>I have a page where the user can enter "from date" and "to date" and get a set of values based on the date-intervall. The only problem is that it isn't working with the "to date".
  When I enter something like this: <code>from: 2012-01-01 | to: 2013-07-26</code> it works fine. But when I try something like this: <code>from: 2010-07-04 | to: 2012-01-01</code> I still get all results AFTER that date aswell (like from 2013).</p>
  
  <p>I've run a debug using the input values above (2010/07/04-2012/01/01). Here is my code along with the relevant values from the debug:</p>
  
  <p><strong>ASPX</strong></p>
  
  <pre><code>    &lt;asp:TextBox ID="VolumeSearchFromDate" runat="server" CssClass="dateTextBox" /&gt;
      &lt;br /&gt;
      &lt;asp:TextBox ID="VolumeSearchToDate" runat="server" CssClass="dateTextBox" /&gt;
      &lt;br /&gt;
      &lt;asp:Button ID="Button2" runat="server" Text="Search" onclick="btnVolumeSearch_Click" ValidationGroup="validate" /&gt;
      &lt;br /&gt;
      &lt;asp:GridView ID="myGv" runat="server" 
      ShowFooter="True" 
      AutoGenerateColumns="False" AllowSorting="True" DataKeyNames="id" DataSourceID="myObjectDataSource" &gt;
          &lt;Columns&gt;
              //my columns here
          &lt;/Columns&gt;
      &lt;/asp:GridView&gt;
  
  &lt;asp:ObjectDataSource ID="myObjectDataSource" runat="server" 
          DeleteMethod="myDeleteMethod" SelectMethod="mySelectMethod" 
          TypeName="whereItsAt.sqlDataLayer" UpdateMethod="myUpdateMethod"&gt;
          &lt;DeleteParameters&gt;
              &lt;asp:Parameter Name="id" Type="Int32" /&gt;
          &lt;/DeleteParameters&gt;
          &lt;SelectParameters&gt;
              &lt;asp:Parameter Name="fromDate" Type="DateTime"/&gt;
              &lt;asp:Parameter Name="toDate" Type="DateTime"/&gt;
          &lt;/SelectParameters&gt;
          &lt;UpdateParameters&gt;
              &lt;asp:Parameter Name="id" Type="Int32" /&gt;
              &lt;asp:Parameter Name="volume" Type="Int32" /&gt;
          &lt;/UpdateParameters&gt;
      &lt;/asp:ObjectDataSource&gt;
  </code></pre>
  
  <p><strong>Code behind (c#)</strong></p>
  
  <pre><code>//dont know why this is here. The person who wrote the code 
  //in the first place wrote this and I haven't removed it.
  protected void btnVolumeSearch_Click(object sender, EventArgs e) 
  {
      gvVolumeListBindData();
  }
  
  private void gvVolumeListBindData()
  {
      myObjectDataSource.SelectParameters.Remove(myObjectDataSource.SelectParameters["fromDate"]);
      string debugString /* "" */= VolumeSearchFromDate.Text.ToString(); /* 2010-04-07 */
      string debugString2 /* 2012-01-01 */ = debugString /* "" */;
      myObjectDataSource.SelectParameters.Add("fromDate", VolumeSearchFromDate.Text.ToString());
      myObjectDataSource.SelectParameters.Remove(myObjectDataSource.SelectParameters["toDate"]);
      myObjectDataSource.SelectParameters.Add("toDate", VolumeSearchToDate.Text.ToString());
      debugString /* "" */ = VolumeSearchToDate.Text.ToString(); /* 2012-01-01
      debugString2 /* 2012-01-01 */ = debugString; /* "" */
  
      gvVolumeList.DataBind();
  }
  </code></pre>
  
  <p><strong>Method for retrieving data (also C#)</strong></p>
  
  <pre><code>public static DataTable mySelectMethod(DateTime fromDate /* 2010-07-04 00:00:00 */, DateTime toDate /* 2013-07-26 00:00:00 */)
  {
      DateTime minDate = new DateTime(1900,01,01,00,00,00);
      DateTime maxDate = DateTime.Today;
  
      int result = DateTime.Compare(minDate, fromDate);
  
      if (result &gt;= 0)
      {
          fromDate = minDate;
      }
  
      result = DateTime.Compare(maxDate, toDate);
  
      if (result &gt;= 0)
      {
          toDate = maxDate;
      }
  
      //set up connection, call stored procedure etc etc etc.
  
      return table;
  }
  </code></pre>
  
  <p>So do anyone understand what's going on here? Seems to me that my variables just randomly change values from time to time.</p>
  
  <p><strong>EDIT</strong>
  The problem was that I was only checking if fromDate was too small and if toDate was to big, but I needed to check both. Thanks to Md. Parvez Alam and Can Canbek for helping me get to that conclusion :)</p>