Results 1 to 4 of 4
  1. #1
    Join Date
    May 2004
    Posts
    2

    Unanswered: Using a datetime parameter with a stored procedure (VC++)

    bool CLogBuilderDlg::OpenResultSet( _ConnectionPtr connection, _RecordsetPtr recordset, COleDateTime start_date)
    {
    _CommandPtr objCmd = NULL;
    objCmd.CreateInstance(__uuidof(Command));
    _variant_t date;
    date = start_date;
    date.vt = VT_DATE;

    try
    {
    objCmd->ActiveConnection = connection;
    objCmd->CommandText = "get_voted_breakdown_test";
    objCmd->CommandType = adCmdStoredProc;
    objCmd->Parameters->Append(objCmd->CreateParameter("@start_date", adDate, adParamInput, 8, date));
    recordset->CursorLocation = adUseClient;
    recordset->Open( (IDispatch *)objCmd, vtMissing, adOpenStatic, adLockReadOnly, adCmdStoredProc );


    etc..etc


    I get the following error:

    Error number 80040e21 [Microsoft] [ODBC SQL server driver] Optional feature not implemented.



    the stored procedure is declared as follows:
    create procedure get_voted_breakdown_test (@start_date datetime) as
    .....

    and it works fine if I call it from the query analyser.



    Searching the microsoft site I found this comment regarding similar problems with VB.

    When the sample code is run, it gives this error:

    Run-time error '2147217887 (80040e21)':
    [Microsoft][ODBC SQL Server Driver] Optional feature not Implemented.
    This is because SQL Server does not support the adDBDate datatype. To correct this problem, change the datatype of the @theDate parameter to adDBTimeStamp.




    So what C++ datatype should I be using?





    Thanx

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Code:
    objCmd->Parameters->Append(objCmd->CreateParameter("@start_date", adTimestamp, adParamInput, 8, date));
    -PatP

  3. #3
    Join Date
    May 2004
    Posts
    2
    Hello Pat,

    I've tried your suggestion (well using the adDBTimeStamp datatype)

    Now I get a different error from the open.

    Error Number 80040e14 procedure get voted breakdown test expects parameter @start_date which was not supplied.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Take a look at the CreateParameter example provided in MSDN. In particular, look at the sections right after
    Code:
    //Define Integer/variant.
    to see how they get the parameter from the user and set it up for the call.

    Check the parameter type enus to see which one matches the parameter you are supplying.

    -PatP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •