ADO 调用存储过程 结果集不对
我用下面的代码调用自定义的存储过程,调用完Execute都没有问题。但是当调用pRst->MoveFirst();这一句时,就挂了,跳到Exception了。。。请问有没有大侠能帮忙分析下?谢谢!
::CoInitialize(NULL);
{
_bstr_t strConn(szConn);
_ConnectionPtr pConnection = NULL;
_RecordsetPtr pRst = NULL;
_CommandPtr pCmd = NULL;
while(true)
{
try
{
hr = pConnection.CreateInstance(_uuidof(Connection));
if(SUCCEEDED(hr))
{
pConnection->Open(strConn, "", "", adConnectUnspecified);
pRst.CreateInstance(__uuidof(Recordset));
pCmd.CreateInstance(__uuidof(Command));
pCmd->ActiveConnection = pConnection;
//pCmd->ActiveConnection->PutCursorLocation(adUseClient);
pCmd->CommandText = _bstr_t(_T("bpGetContInsMin"));
pCmd->CommandType = adCmdStoredProc;
_ParameterPtr pParamIndex = NULL;
pParamIndex.CreateInstance(__uuidof(Parameter));
pParamIndex = pCmd->CreateParameter(_T("pInsID"), adInteger, adParamInput, sizeof(int));
pParamIndex->Value = _variant_t(index);
pCmd->Parameters->Append(pParamIndex);
_ParameterPtr pParamDays = NULL;
pParamDays.CreateInstance(__uuidof(Parameter));
pParamDays = pCmd->CreateParameter(_T("pMaxDays"), adInteger, adParamInput, sizeof(int));
pParamDays->Value = _variant_t(days);
pCmd->Parameters->Append(pParamDays);
pRst = pCmd->Execute(NULL, NULL, adCmdStoredProc);
}
pRst->MoveFirst();
if(pRst->rsEOF || pRst->BOF)
{
dwRealCount = 0;
break;
}
_variant_t avarRecords;
avarRecords = pRst->GetRows(adGetRowsRest);
dwRealCount = ParseQueryResults(pBuffer, avarRecords, true);
pRst->Close();
pConnection->Close();
break;
}
catch(_com_error &e)
{
printf("ADO Recordset Open failed. ErrorMsg = %s\n", e.ErrorMessage());
continue;
}
}
}
------解决方案--------------------
但是当调用pRst->MoveFirst();这一句时,就挂了,
应该是结果集是空集,你先判断如果结果集不为空再执行这一句.
建议你检查你的sql语句和查询条件,测试在查询分析器里运行是否有记录集?