• Parameter query and ADO in code

    • This topic has 0 replies, 1 voice, and was last updated 24 years ago.
    Author
    Topic
    #355962

    I want to use a parameter query from a C++ based program with ADO. I suspect that I am not using the correct information for the ADO Command. Can anyone suggest what may be required.

    The code gives an error message:-
    Item canot be found in the collection corresponding to the requested name or ordinal.

    The query in Access starts with:-
    PARAMETERS lBereich Long, dteFrom DateTime, dteTo DateTime;
    SELECT

    and the code is:-
    _CommandPtr pCmd(“ADODB.Command”);
    pCmd->ActiveConnection = pCn;
    pCmd->CommandText = _T(“Controlling_IndKost_Eigenes”);
    pCmd->CommandType = adCmdStoredProc;
    pCmd->Parameters->Refresh();

    pCmd->Parameters->Item[_bstr_t(L”lBereich”)]->Value = _variant_t((long) m_iBereich);
    pCmd->Parameters->Item[_bstr_t(L”dteFrom”)]->Value = _variant_t((double) dteFrom.m_dt);
    pCmd->Parameters->Item[_bstr_t(L”dteTo”)]->Value = _variant_t((double) dteTo.m_dt);
    pRS = pCmd->Execute( NULL, NULL, adCmdStoredProc );

    If I use the following code then it works perfectly:-
    _CommandPtr pCmd(“ADODB.Command”);
    pCmd->ActiveConnection = pCn;
    pCmd->CommandText = _T(“Controlling_IndKost_Eigenes”);
    pCmd->CommandType = adCmdStoredProc;

    pCmd->Parameters->Append(pCmd->CreateParameter(“lBereich”, adBigInt, adParamInput, sizeof(long)));
    pCmd->Parameters->Append(pCmd->CreateParameter(“dteFrom”, adDate, adParamInput, sizeof(double)));
    pCmd->Parameters->Append(pCmd->CreateParameter(“dteTo”, adDate, adParamInput, sizeof(double)));

    pCmd->Parameters->Item[_bstr_t(L”lBereich”)]->Value = _variant_t((long) m_iBereich);
    pCmd->Parameters->Item[_bstr_t(L”dteFrom”)]->Value = _variant_t((double) dteFrom.m_dt);
    pCmd->Parameters->Item[_bstr_t(L”dteTo”)]->Value = _variant_t((double) dteTo.m_dt);
    pRS = pCmd->Execute( NULL, NULL, adCmdStoredProc );

    Win 2000 SP1.
    Access 2000 (German, no SP).
    Visual Studio 6 (SP 5).
    MSDAC_TYP installed (2.6)

    Reply To: Parameter query and ADO in code

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: