Solved

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

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Runtime Exceptions when trying to submit data 28 51
Gridview selected row 9 43
How to have a gridview column with multiple items in a column row. 2 22
Deploying to Azure 3 26
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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

815 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now