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") ...

+ Reply to Thread
Results 1 to 2 of 2

Pass datetime paramater to SQL Stored Proc in ASP

  1. Default 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




  2. Default 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"



+ Reply to Thread

Similar Threads

  1. Unable to pass DBDATE to stored-proc using ADO/C++
    By Application Development in forum ADO DAO RDO RDS
    Replies: 1
    Last Post: 11-08-2007, 06:22 PM
  2. Replies: 0
    Last Post: 10-29-2007, 06:18 PM
  3. Replies: 0
    Last Post: 10-19-2007, 03:09 PM
  4. Portable way to pass array parameter to a stored proc?
    By Application Development in forum JDBC JAVA
    Replies: 2
    Last Post: 02-06-2005, 01:27 PM
  5. Pass a datetime param to proc/fcn to the Visual Studio "Run Dialog
    By Application Development in forum DOTNET
    Replies: 3
    Last Post: 01-24-2005, 07:33 AM