demo10.cpp

来自「《AE库通用模块及典型系统开发实例导航》光盘内容分享!」· C++ 代码 · 共 56 行

CPP
56
字号
// 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("Password"))<<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;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?