CString strConn = _T("Provider='sqloledb';Data Source=xxx.xxx.xxx.xxx;Initial Catalog=xxxx;User ID=xx");
CString strSQLFunction = _T("SELECT * FROM [af_xxx] ()");
try
{
ADODB::_RecordsetPtr pRecordSet = 0;
pRecordSet.CreateInstance(_T("ADODB.RecordSet"));
ASSERT(pRecordSet);
pRecordSet->Open(_bstr_t(strSQLFunction),_bstr_t(strConn),ADODB::adOpenForwardOnly,ADODB::adLockReadOnly,ADODB::adCmdText);
pRecordSet->MoveFirst();
while (!pRecordSet->adoEOF)
{
_bstr_t bstrHashSet = pRecordSet->Fields->Item["colName"]->Value;
pRecordSet->MoveNext();
}
pRecordSet->Close();
//pRecordSet->Release();//会自动释放,不用显示调用释放过程
{
ADODB::_RecordsetPtr pRecordSet = 0;
pRecordSet.CreateInstance(_T("ADODB.RecordSet"));
ASSERT(pRecordSet);
pRecordSet->Open(_bstr_t(strSQLFunction),_bstr_t(strConn),ADODB::adOpenForwardOnly,ADODB::adLockReadOnly,ADODB::adCmdText);
pRecordSet->MoveFirst();
while (!pRecordSet->adoEOF)
{
_bstr_t bstrHashSet = pRecordSet->Fields->Item["colName"]->Value;
pRecordSet->MoveNext();
}
pRecordSet->Close();
//pRecordSet->Release();//会自动释放,不用显示调用释放过程
}
catch(_com_error &e)
{
AfxMessageBox(e.Description());
catch(_com_error &e)
{
AfxMessageBox(e.Description());
}