m_pRecordset->Open("SELECT * FROM racer",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
整个程序就提示这里错了
将这里去掉,正常,但是抛出异常...错误如下:
D:\Microsoft Visual Studio\MyProjects\Fishing\FishingDlg.cpp(142) : error C2065: 'theApp' : undeclared identifier
D:\Microsoft Visual Studio\MyProjects\Fishing\FishingDlg.cpp(142) : error C2228: left of '.m_pConnection' must have class/struct/union type
请问为什么...
我是照着例子做的...
整个程序就提示这里错了
将这里去掉,正常,但是抛出异常...错误如下:
D:\Microsoft Visual Studio\MyProjects\Fishing\FishingDlg.cpp(142) : error C2065: 'theApp' : undeclared identifier
D:\Microsoft Visual Studio\MyProjects\Fishing\FishingDlg.cpp(142) : error C2228: left of '.m_pConnection' must have class/struct/union type
请问为什么...
我是照着例子做的...
忘了看他的说明了,呵呵内存泄露,结贴时给你分. int nItem;
extern CFishingApp theApp;
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open("SELECT * FROM racer",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
while(!m_pRecordset->adoEOF)
{
vID = m_pRecordset->GetCollect("RacerID");
vName = m_pRecordset->GetCollect("RacerName");
vA1 = m_pRecordset->GetCollect("Amount1");
vAP1 = m_pRecordset->GetCollect("AmountPoint1");
nItem=m_InfoList.InsertItem(0xffff,(_bstr_t)vID);
m_InfoList.SetItem(nItem,1,1,(_bstr_t)vName,NULL,0,0,0);
m_InfoList.SetItem(nItem,2,1,(_bstr_t)vA1,NULL,0,0,0);
m_InfoList.SetItem(nItem,3,1,(_bstr_t)vAP1,NULL,0,0,0);
m_pRecordset->MoveNext();
}
}
catch(_com_error e)///捕捉异常
{
AfxMessageBox("读取数据库失败!");///显示错误信息
}
return TRUE; // return TRUE unless you set the focus to a control这个为什么老是读取数据库失败呢...
我在racer.mdb中定义了几个字段,不只上面提取的那些...我只是以那四个试一试..
但是却总是提取失败.
m_InfoList.SetItem(nItem,1,1,(_bstr_t)vName,NULL,0,0,0);
m_InfoList.SetItem(nItem,2,1,(_bstr_t)vA1,NULL,0,0,0);
m_InfoList.SetItem(nItem,3,1,(_bstr_t)vAP1,NULL,0,0,0);
这个我试过,还是出现错误to:内存泄露
这个初始化我在app的inistance中完成了.
我在create前面又加了一次,出现异常终止程序...
{
AfxMessageBox("读取数据库失败!");///显示错误信息
}你把上面的改成下面的样子,返回异常说明看看是什么异常。。catch(_com_error &e)
{
AfxMessageBox(e.Description());
}