菜鸟提问
按照教材上说的:
BOOL CADOTest1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr))
{
hr = m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=test.mdb","","",adModeUnknown);///连接数据库
//上面一句中连接字串中的Provider是针对ACCESS2000环境的,对于ACCESS97,
//需要改为:Provider=Microsoft.Jet.OLEDB.3.51;
}
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!rn错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
}
我写了以上代码,编译后出现问题:
1>d:\my documents\visual studio 2008\projects\learning access\learning access\learning access.cpp(45) : error C2065: “m_pConnection”: 未声明的标识符
我已经在stdAfx.h中写了
#import "c:\program files\common files\system\ado\msado15.dll" \
no_namespace \
rename ("EOF", "adoEOF")
怎么解决呢?急!!!