ADO调用存储过程如何指定参数?
我用了下面的代码来调用一个存储过程
gen_menu(@uno Integer, @level Integer, @lastselect varchar(50))
在运行时总是抛出异常“至少一个参数没有被指定值”,怎么办啊?
下面是测试的存储过程和ADO代码
CREATE PROCEDURE gen_menu(
@uno Integer,@level Integer,@lastselect varchar(50)
) AS
select * from test
GO
_RecordsetPtr rs(__uuidof(Recordset));
rs.CreateInstance(__uuidof(Recordset));//初始化Recordset指针
BOOL ret=TRUE;
long cnt=0;
try{
//--------------------------------------------------------
m_pcommand->PutCommandText(L"call {gen_menu(?,?,?)}");
m_pcommand->PutCommandType(adCmdStoredProc);
m_pcommand->PutCommandTimeout(1000);
_ParameterPtr paramptr;
paramptr = m_pcommand->CreateParameter(_bstr_t("uno"),adInteger,adParamInput,sizeof(long), (long)uno);
m_pcommand->GetParameters()->Append(paramptr);
paramptr = m_pcommand->CreateParameter(_bstr_t("level"),adInteger,adParamInput,sizeof(long), (long)level);
m_pcommand->GetParameters()->Append(paramptr);
paramptr = m_pcommand->CreateParameter(_bstr_t("lastselect"),adVarChar,adParamInput,lastselect.GetLength()+1, _variant_t(lastselect));
m_pcommand->GetParameters()->Append(paramptr);
rs->Open((_Command*)m_pcommand,vtMissing,adOpenForwardOnly,adLockOptimistic,adCmdStoredProc);
rs->Fields->get_Count(&cnt);
if(cnt!=1) ret=FALSE;
else{
v.clear();
while(!rs->Get_EOF()){
string =(LPCTSTR)_bstr_t(rs->GetCollect(L"prop_value"));
v.push_back(s);
}
}
//--------------------------------------------------------
}
catch(_com_error& e){
ErrorsPtr pErrors=m_pconnection->GetErrors();
if(pErrors->GetCount()==0)
{
AfxMessageBox(e.ErrorMessage());
}
else
{
for(int i=0;i<pErrors->GetCount();i++)
{
_bstr_t esc=pErrors->GetItem((long)i)->GetDescription();
AfxMessageBox(desc);
}
}
}
catch(...)
{
AfxMessageBox("some exception occured");
}
rs->Close();
return ret;