?
Solved

Minimum datetime value in ASP.NET and Stored procedure question.

Posted on 2008-10-21
1
Medium Priority
?
647 Views
Last Modified: 2012-05-05
In one ASP.NET page, I have to use below value for the min value and max value for searching the results. The reason is the different min value and max value in ASP.NET and in SQL Server. I know it's stupid, but when I used: string MinValue = "12/12/1800"; string MaxValue = "12/12/2050"
in both asp page and the stored procedure, the search function works. But what is the better way (for sure there is) to replace the '12/12/1800', etc. in both asp page and stored procedure and will for sure WORK? Thanks.

#1: search.aspx:
public static DataTable GetSearchResults(string StartDateFrom,string StartDateTo,)
      string MinValue = "12/12/1800";
      string MaxValue = "12/12/2050";
      comm.CommandText = "GetSearchResults";

      if (StartDateFrom == "" & StartDateTo == "")
      {
          StartDateFrom = Convert.ToDateTime(MinValue).ToString();
          StartDateTo = Convert.ToDateTime(MaxValue).ToString();
      }

      param = comm.CreateParameter();
      param.ParameterName = "@StartDateFrom";
      param.Value = StartDateFrom;
      param.DbType = DbType.DateTime;
      comm.Parameters.Add(param);

...
     return GenericDataAccess.ExecuteSelectCommand(comm);        

#2  Stored procedure detail (called in #1):

...
CREATE PROCEDURE GetSearchResultsFiltered    
@StartDateFrom datetime,                  
@StartDateTo datetime
...
AS
DECLARE @MinValue DATETIME    
DECLARE @MaxValue DATETIME    
SET @MinValue = '12/12/1800'    
SET @MaxValue = '12/12/2050'    

IF (@StartDateFrom = @MinValue and @StartDateTo = @MaxValue)    
BEGIN    
SET @StartDateFrom = null    
SET @StartDateTo = null    
END    

select * from ...
where ...
AND ((@StartDateFrom is null) OR (StartDate > @StartDateFrom - 1))      
AND ((@StartDateTo is null) OR (StartDate < @StartDateTo + 1))    

...
0
Comment
Question by:heyday2004
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 13

Accepted Solution

by:
crazyman earned 1500 total points
ID: 22765643
You could use
DateTime.MinValue
and
DateTime.MaxValue

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question