【VC开源代码栏目提醒】:网学会员VC开源代码为您提供Demo10.cpp参考,解决您在Demo10.cpp学习中工作中的难题,参考学习。
// ADODemo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream.h"
//导入ADO类型库
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "EndOfFile")
int main(int argc, char* argv[])
{
CoInitialize(NULL);
_ConnectionPtr pConn("ADODB.Connection");
try
{
pConn->ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Demo.mdb;Persist Security Info=False";
pConn->Open("", "", "", adConnectUnspecified);
_CommandPtr pCmd("ADODB.Command");
pCmd->ActiveConnection = pConn;
pCmd->CommandText = "UserInfo";
_RecordsetPtr pRs = pCmd->Execute(NULL, NULL, adCmdTable);
while(!pRs->EndOfFile)
{
cout<<"UserName:"<<_bstr_t(pRs->GetCollect("UserName"))<<"\t";
cout<<"Password:"<<_bstr_t(pRs->GetCollect("Pass
word"))<<endl;
pRs->MoveNext();
}
pConn->Close();
}
catch(_com_error &e)
{
cout<<e.ErrorMessage()<<endl;
for(long i = 0; i < pConn->Errors->Count; i++)
{
cout<<pConn->Errors->GetItem(_variant_t(i))->Description<<endl;
}
}
CoUninitialize();
return 0;
}