⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo5.cpp

📁 《AE库通用模块及典型系统开发实例导航》光盘内容分享!
💻 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[])
{
	//初始化Com对象
	CoInitialize(NULL);

	try
	{
		//初始化数据库连接对象
		_ConnectionPtr pConn("ADODB.Connection");
		//打开数据库连接
		pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Demo.mdb;Persist Security Info=False", "", "", adConnectUnspecified);
		
		_RecordsetPtr pRs;
		
		pRs = pConn->Execute("UserInfo", 0, adCmdTable);
	
		while(!pRs->EndOfFile)
		{
			cout<<"UserName:"<<_bstr_t(pRs->GetCollect("UserName"))<<"\t";
			cout<<"Password:"<<_bstr_t(pRs->GetCollect("Password"))<<endl;
			pRs->MoveNext();
		}

		//关闭记录集
		pRs->Close();
		//关闭数据库连接
		pConn->Close();

	}
	catch(_com_error &e)
	{
		cout<<e.ErrorMessage()<<endl;
	}
	return 0;
}

⌨️ 快捷键说明

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