Solved

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

Posted on 2008-10-21
1
636 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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