// Access.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
int _tmain(int argc, _TCHAR* argv[])
{
_ConnectionPtr m_pConnection;
OleInitialize(NULL);
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");
if(SUCCEEDED(hr))
{
hr = m_pConnection->Open("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = test.mdb", "", "", adModeUnknown);
}
}
catch(_com_error e)
{
printf("连接数据库失败!错误%d",e.ErrorMessage());
//return 0;
}
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance("ADODB.Recordset");
//Connection对象的Execuet方法/
_variant_t RecordsAffected;
m_pConnection->Execute("create table users(ID INTEGER, username TEXT, old INTEGER, birthday DATETIME)",&RecordsAffected,adCmdText);
m_pConnection-&g
C++利用ADO连接Access
最新推荐文章于 2018-11-13 15:10:00 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)