Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Building a WhereClause with Date parameters.
Message
De
22/03/2007 13:52:21
Alexandre Palma
Harms Software, Inc.
Alverca, Portugal
 
Information générale
Forum:
ASP.NET
Catégorie:
Web Services
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01207183
Message ID:
01207250
Vues:
21
now this is some starting point as you can see I don't create any connection object.
Note that since you said you want only deal with dates that's why I create a new date for the parameters, so it doesn't care what is the time you pass.
	public string test(System.DateTime startDate, System.DateTime endDate)
	{
		string functionReturnValue = null;
		System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("Select * FROM mytable WHERE datecol >= @StartDate And datecol<@EndDate");
		System.Data.SqlClient.SqlParameter par;
		par = cmd.Parameters.Add("@StartDate", SqlDbType.DateTime);
		par.Value = new System.DateTime(startDate.Year, startDate.Month, startDate.Day, 0, 0, 0);
		par = cmd.Parameters.Add("@EndDate", SqlDbType.DateTime);
		par.Value = new System.DateTime(endDate.Year, endDate.Month, endDate.Day, 0, 0, 0).AddDays(1);
		cmd.ExecuteReader();
		return functionReturnValue;
	}
>Good Question,
>
>the tables I'll be working on are using DateTime Fields. But I'll be sending just two dates and I would want them to be all encompassing dates. Should I then just add a time of 00:00:00 for the startdate and a time of 23:59:59 for the endtime? or is there a better way?
>
>Thanks again,
>Paul
>
>>...and a follow-up....do you care about the time within the date? Or just the date?
>>
>>Kevin
Alexandre Palma
Senior Application Architect
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform