Pass datetime paramater to SQL Stored Proc in ASP - Inetserver
This is a discussion on Pass datetime paramater to SQL Stored Proc in ASP - Inetserver ; I get the following error while trying to execute a stored proc
Application uses a value of the wrong type for the current operation.
heres the ASP Code
sfrmDate = Request.Form("frmMonth") & Request.Form("frmDate") & Request.Form("frmYear")
stoDate = Request.Form("toMonth") & Request.Form("toDate") ...
-
Pass datetime paramater to SQL Stored Proc in ASP
I get the following error while trying to execute a stored proc
Application uses a value of the wrong type for the current operation.
heres the ASP Code
sfrmDate = Request.Form("frmMonth") & Request.Form("frmDate") & Request.Form("frmYear")
stoDate = Request.Form("toMonth") & Request.Form("toDate") & Request.Form("toYear")
cmdMailSearch.Parameters.Append cmdMailSearch.CreateParameter("@DateFrom",adDBTimeStamp,adParamInput,0,sfrmDate)
cmdMailSearch.Parameters.Append cmdMailSearch.CreateParameter("@DateTo",adDBTimeStamp,adParamInput,0,stoDate)
heres the SP
CREATE PROCEDURE procSearchDateRange
(
@DateFrom datetime,
@DateTo datetime
)
AS
begin
Select EmpID,EmpEmailID,EmpFirstName,EmpLastName,EmpDateOfBirth,EmpDateOfJoining,EmpContactNo,DateCreated from tblEmployee
WHERE EmpDateOfBirth >= CONVERT(datetime,@DateFrom) and EmpDateOfBirth < Convert(datetime,@DateTo)
end
What am I doing wrong?
regards,
Rohan
-
Re: Pass datetime paramater to SQL Stored Proc in ASP
jordan wrote:
> I get the following error while trying to execute a stored proc
>
>
> Application uses a value of the wrong type for the current operation.
>
> heres the ASP Code
>
>
> sfrmDate = Request.Form("frmMonth") & Request.Form("frmDate") &
> Request.Form("frmYear")
> stoDate = Request.Form("toMonth") & Request.Form("toDate") &
> Request.Form("toYear")
>
> cmdMailSearch.Parameters.Append
> cmdMailSearch.CreateParameter("@DateFrom",adDBTimeStamp,adParamInput,0,sfrmDate)
> cmdMailSearch.Parameters.Append
> cmdMailSearch.CreateParameter("@DateTo",adDBTimeStamp,adParamInput,0,stoDate)
>
>
>
>
> What am I doing wrong?
>
You are passing a string instead of a date. Worse, you are passing a string
containing an improperly formatted date. A better technique would be:
sfrmDate = DateSerial(Request.Form("frmYear"), _
Request.Form("frmMonth"), Request.Form("frmDate") )
In addition, your procedure is not using output parameters, so you really
don't need an explicit Command object (although, it really does not hurt to
use one). See this post for my preferred technique:
http://groups.google.com/group/micro...9dc1701?hl=en&
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Similar Threads
-
By Application Development in forum ADO DAO RDO RDS
Replies: 1
Last Post: 11-08-2007, 06:22 PM
-
By Application Development in forum ADO DAO RDO RDS
Replies: 0
Last Post: 10-29-2007, 06:18 PM
-
By Application Development in forum ADO DAO RDO RDS
Replies: 0
Last Post: 10-19-2007, 03:09 PM
-
By Application Development in forum JDBC JAVA
Replies: 2
Last Post: 02-06-2005, 01:27 PM
-
By Application Development in forum DOTNET
Replies: 3
Last Post: 01-24-2005, 07:33 AM