用ADO调用存储过程时出现了一个错误
我在用ADO调用存储过程时出现了一个错误,大家给分析分析
存储过程:
CREATE PROCEDURE Execjw1 @ywpos int,@st tinyint output
AS
begin
select fstatus from sljw where fid=@ywpos
end
调用存储过程:
::CoInitialize(NULL);
_variant_t TheValue,var1,var2;
_ParameterPtr para1,para2;
CString strOpen="DSN=agent;UID=;PWD=";
try
{
m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->Open((const char *)strOpen,"","",-1);
}
catch(...)
{
AfxMessageBox("数据库初始化错误,程序将关闭!");
return FALSE;
}
int fid=23; //(传入参数值)
var1.vt=VT_I4;
var1.lVal=fid;
_bstr_t strSProc=L"Execjw1";
m_pCommand.CreateInstance(__uuidof(Command));
m_pCommand->ActiveConnection=m_pConnection;
m_pCommand->CommandText=_bstr_t(strSProc);
m_pCommand->CommandType=adCmdStoredProc;
===========================================
m_pRecordset->PutRefSource(m_pCommand); (单步调试出错)
===========================================
para1=m_pCommand->CreateParameter("@ywpos",adInteger,
adParamInput,sizeof(int),var1);
m_pCommand->Parameters->Append(para1);
para2=m_pCommand->CreateParameter("@st",adTinyInt,
adParamOutput,1,vtMissing);
m_pCommand->Parameters->Append(para2);
_variant_t vNull;
vNull.vt=VT_ERROR;
vNull.scode=DISP_E_PARAMNOTFOUND;
try
{
m_pRecordset->Open(vNull,vNull,adOpenForwardOnly,adLockReadOnly,
adCmdStoredProc);
while(!m_pRecordset->EndOfFile)
{
TheValue=m_pRecordset->GetCollect(_variant_t("FStatus"));
if(TheValue.vt!=VT_NULL)
{
TheValue.ChangeType(VT_BSTR);
CString strTheValue=TheValue.bstrVal;
m_List.AddString((char*)_bstr_t(TheValue));//在列表框中显示FStatus字段值
}
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
m_pCommand->Release();
m_pConnection->Close();
::CoUninitialize();
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
catch(...)
{
AfxMessageBox("error");
}
m_pRecordset=NULL;
m_pCommand=NULL;
m_pConnection=NULL;
编译通过了,但是执行时程序异常终止,单步调试时运行到上面那句就出错了,出现一个提示框说:Unhandle exception in adotest.ext(KERNEL32.DLL):0xE06D7363:Microsoft C++ Exception
不知道哪里错了?