m_pRecordSet.CreateInstance("ADODB.Recordset");
#ifdef _DEBUG
if (m_pRecordSet == NULL)
{
AfxMessageBox("RecordSet 對象創建失敗! 請確認是否初始化了COM環境.");
return;
}
#endif
ASSERT(m_pRecordSet != NULL);
CString sql="TestGet";
int i,recordcount;
try
{
m_pRecordSet->Open((_variant_t)sql,_variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdStoredProc);
recordcount=m_pRecordSet->GetRecordCount();//Get records total.
if(!m_pRecordSet->adoEOF)
{
for(i=0;i<recordcount;i++)
{
AfxMessageBox((LPCTSTR)(_bstr_t)m_pRecordSet->GetCollect("Account"));
m_pRecordSet->MoveNext();
}
}
m_pRecordSet->Close();
}
catch(_com_error e)
{
CString temp;
temp.Format(_T("Warning: 打開記錄集發生異常. 錯誤信息: %s; 文件: %s; 行: %d "), e.ErrorMessage(), __FILE__, __LINE__);
AfxMessageBox(temp);
}
如果不用存儲過程將sql變量改成sql語句就可以了.