_CommandPtr m_pCommand;
_ParameterPtr recnum;
m_pCommand.CreateInstance(__uuidof(Command));
m_pCommand->ActiveConnection=theApp.m_pCon;
m_pCommand->CommandText="testinfo";
m_pCommand->CommandType=adCmdStoredProc;recnum.CreateInstance(__uuidof(Parameter));recnum=m_pCommand->CreateParameter("ccc",adInteger,adParamOutput,4);
m_pCommand->Parameters->Append(recnum);

_variant_t vNull;
 vNull.vt=VT_ERROR;
 vNull.scode=DISP_E_PARAMNOTFOUND;
theApp.m_pRec=m_pCommand->Execute(&vNull,&vNull,adCmdStoredProc);
_variant_t var;
var=recnum->value;
这里var得到为空,请教各位怎样才能得到输出参数的值

解决方案 »

  1.   

    maybe this can function
    _variant_t var;
    var=m_pCommand->GetParameters()->GetItem(0)->Value;//return code
    var=m_pCommand->GetParameters()->GetItem(1)->Value;//output parameter
      

  2.   

    检查一下你的存储过程有没有给Output赋值。
      

  3.   

    我的存储过程在Query Analyzer中测试是没有问题的,能够打印输出
    AkiraChing:我的存储过程没有返回值,我用过:var=m_pCommand->GetParameters()->GetItem((short)0)->Value;返回为空,如果用var=m_pCommand->GetParameters()->GetItem((short)1)->Value就会有异常了
      

  4.   

    m_pRecordset = cmd->Execute(NULL, NULL, adCmdStoredProc); //return (char*)_bstr_t(pParamOk->Value);
    _variant_t varBLOB;
    int i =  m_pRecordset->GetFields()->GetItem("job_id")->ActualSize; CString str = (char*)_bstr_t(m_pRecordset->GetFields()->GetItem("job_id")->Value);
    AfxMessageBox( str );
    return str;