Pass datetime paramater to SQL Stored Proc in ASP

Pass datetime paramater to SQL Stored Proc in ASP

am 30.07.2006 07:33:46 von unknown

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,adPa ramInput,0,sfrmDate)
cmdMailSearch.Parameters.Append cmdMailSearch.CreateParameter("@DateTo",adDBTimeStamp,adPara mInput,0,stoDate)




heres the SP

CREATE PROCEDURE procSearchDateRange
(
@DateFrom datetime,
@DateTo datetime
)

AS
begin
Select EmpID,EmpEmailID,EmpFirstName,EmpLastName,EmpDateOfBirth,Emp DateOfJoining,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

am 30.07.2006 14:10:06 von reb01501

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,adPa ramInput,0,sfrmDate)
> cmdMailSearch.Parameters.Append
> cmdMailSearch.CreateParameter("@DateTo",adDBTimeStamp,adPara mInput,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/microsoft.public.inetserver.a sp.general/msg/5d3c9d4409dc1701?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"