Groups | Blog | Home
all groups > inetserver asp db > july 2006 >

inetserver asp db : Pass datetime paramater to SQL Stored Proc in ASP



jordan
7/29/2006 10:33:46 PM
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


Bob Barrows [MVP]
7/30/2006 8:10:06 AM
[quoted text, click to view]
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.asp.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"

AddThis Social Bookmark Button