在头文件中声明错误,这种变量怎么声明,我是这么声明的,
_ConnectionPtr m_pConnection;
_CommandPtr m_pCommand;
_RecordsetPtr m_pRecordset;结果报错说
c:\documents and settings\emir\my documents\access\access.h(32) : error C2146: syntax error : missing ';' before identifier 'm_pConnection'
c:\documents and settings\emir\my documents\access\access.h(32) : error C2501: '_ConnectionPtr' : missing storage-class or type specifiers
c:\documents and settings\emir\my documents\access\access.h(32) : error C2501: 'm_pConnection' : missing storage-class or type specifiers怎么回事呢
_ConnectionPtr m_pConnection;
_CommandPtr m_pCommand;
_RecordsetPtr m_pRecordset;结果报错说
c:\documents and settings\emir\my documents\access\access.h(32) : error C2146: syntax error : missing ';' before identifier 'm_pConnection'
c:\documents and settings\emir\my documents\access\access.h(32) : error C2501: '_ConnectionPtr' : missing storage-class or type specifiers
c:\documents and settings\emir\my documents\access\access.h(32) : error C2501: 'm_pConnection' : missing storage-class or type specifiers怎么回事呢
#import "c:\program files\common files\system\ado\msado27.tlb" no_namespace rename( "EOF", "adoEOF" )
我们可以使用AfxOleInit()来初始化COM库,这项工作通常在CWinApp::InitInstance()的重载函数中完成,请看如下代码:
BOOL CADOTest1App::InitInstance()
{
AfxOleInit(); //这个和对话框工程中使用CRichEditCtrl控件也要先用AfxInitRichEdit();初始化一样
...... 【2】用#import指令引入ADO类型库
我们在stdafx.h中加入如下语句:(stdafx.h这个文件哪里可以找到?你可以在FileView中的Header Files里找到)
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
这一语句有何作用呢?其最终作用同我们熟悉的#include类似,编译的时候系统会为我们生成msado15.tlh,ado15.tli两个C++头文件来定义ADO库。几点说明:
(1) 您的环境中msado15.dll不一定在这个目录下,请按实际情况修改
(2) 在编译的时候肯能会出现如下警告,对此微软在MSDN中作了说明,并建议我们不要理会这个警告。
msado15.tlh(405) : warning C4146: unary minus operator applied to unsigned type, result still unsigned 【3】创建Connection对象并连接数据库
首先我们需要添加一个指向Connection对象的指针:
_ConnectionPtr m_pConnection;
_CommandPtr m_pCommand;
_RecordsetPtr m_pRecordset;