C++ 控制台连接 ADO 读写 access2007 数据库
C++控制台连接ADO读写access2007数据库#include <iostream>
#include<Windows.h>
#include <string.h>
#include <cstdio>
using namespace std;
//导入ADO动态链接库,必须的
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
void main()
{ _ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
CoInitialize(NULL);
m_pConnection.CreateInstance(__uuidof(Connection));
try
{
m_pConnection->Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=../test/stu.accdb;Persist Security Info=False","","",adModeUnknown);
}
catch(_com_error e)
{ cout<<e.ErrorMessage();
return ;
}
m_pRecordset.CreateInstance("ADODB.Recordset");
_variant_t RecordsAffected;
m_pRecordset = m_pConnection->Execute("select * from stu where stu_id='12334'",&RecordsAffected,adCmdText);
cout<<(_bstr_t)(m_pRecordset->GetCollect("stu_name"));
m_pRecordset->Close();
m_pConnection->Close();
}