VC通过ADO链接ORACLE数据库的一个简单的小例子:
Code
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "rsEOF")
CoInitialize(NULL);
_ConnectionPtr pConn(_uuidof(Connection));
_RecordsetPtr pRst(_uuidof(Recordset));
pConn->ConnectionString = _T("Provider=OraOLEDB.Oracle; Data Source=utfgs; User Id=utfgs; Password=utfgs");
pConn->Open("","","",adConnectUnspecified);
pRst = pConn->Execute("select * from equipment",NULL,adCmdText);
while(!pRst->rsEOF)
{
CString item=pRst->GetCollect("equipmentid");
((CListBox*)GetDlgItem(IDC_LIST2))->AddString((_bstr_t)pRst->GetCollect("equipmentid"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "rsEOF")
CoInitialize(NULL);
_ConnectionPtr pConn(_uuidof(Connection));
_RecordsetPtr pRst(_uuidof(Recordset));
pConn->ConnectionString = _T("Provider=OraOLEDB.Oracle; Data Source=utfgs; User Id=utfgs; Password=utfgs");
pConn->Open("","","",adConnectUnspecified);
pRst = pConn->Execute("select * from equipment",NULL,adCmdText);
while(!pRst->rsEOF)
{
CString item=pRst->GetCollect("equipmentid");
((CListBox*)GetDlgItem(IDC_LIST2))->AddString((_bstr_t)pRst->GetCollect("equipmentid"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();