Solved

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

Posted on 2008-10-21
1
633 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 500 total points
ID: 22765643
You could use
DateTime.MinValue
and
DateTime.MaxValue

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 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