全部博文(45)
分类: C/C++
2013-02-24 15:24:17
//项目属性->通配属性->常规->项目默认值->字符集 改为未设置 #include "stdafx.h" #include#include #import "I:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF", "adoEOF") void main() { _ConnectionPtr m_pConnection; //到access数据库的链接对象 _RecordsetPtr m_pRecordset; //结果集对象 CoInitialize(NULL); //初始化 try { m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象 m_pConnection->Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=../data/rule.accdb;Persist Security Info=False","","",adModeUnknown);///连接数据库 } catch(_com_error e)///捕捉异常 { MessageBox(NULL, e.Description(), "连接错误", MB_OK); } m_pRecordset.CreateInstance("ADODB.Recordset"); //创建Recordset对象 _variant_t RecordsAffected; m_pRecordset = m_pConnection->Execute("select * from rule where pre='hsh'",&RecordsAffected,adCmdText); _variant_t result = m_pRecordset->GetCollect("con"); MessageBox(NULL, (char*)(_bstr_t)result, "查询结果", MB_OK); m_pRecordset->Close();///关闭记录集 m_pConnection->Close();///关闭连接 }