How do I use a datetime variable with createparameter in classic ASP?
Posted
by Frank Schmitt
on Stack Overflow
See other posts from Stack Overflow
or by Frank Schmitt
Published on 2010-03-30T23:55:40Z
Indexed on
2010/03/31
0:03 UTC
Read the original article
Hit count: 708
asp-classic
|parameterized-query
I'm having a heck of a time trying to create a parameterized query that binds a date variable into a stored procedure call:
twoyearsago = dateadd("yyyy", -2, date())
DataConn.ConnectionString = myConnectionString
DataConn.Open
Set rs = Server.CreateObject("ADODB.Recordset")
Set DataCmd = Server.CreateObject("ADODB.Command")
DataCmd.ActiveConnection = DataConn
DataCmd.CommandText = "exec myStoredProc ?, ?"
DataCmd.Parameters.Append DataCmd.CreateParameter("@start", adDate, , 10, date())
DataCmd.Parameters.Append DataCmd.CreateParameter("@end", adDate, , 10, twoyearsago)
rs.Open DataCmd
The stored proc returns nothing (indicating the dates aren't making it through). If I hard code dates in the query, e.g.:
DataCmd.CommandText = "exec myStoredProc '01/01/2008', '01/01/2010'"
I get the results I would expect. Calling CStr on my dates (if that makes a difference) returns them in the above format.
© Stack Overflow or respective owner