请各位帮帮我这个初学者呀:谢谢了
程序可以运行到最后一行:AfxMessageBox("Ok!!!!!!");
却出现如下错误:
弹出一个对话框:Unhandled exception in adoimport.exe ox000000000005:Access Violation.
问题说是在:c:...\vc98\include\comip.h
void _Release() throw()
{
if (m_pInterface != NULL) {
m_pInterface->Release();
}
}代码如下:void CAdoimportDlg::OnOK()
{
if(!AfxOleInit())
AfxMessageBox("初始化ADO出错!");
double data[9][11] =
{
{0.5,0.04,0.02,0.009,0.01,0.003,1.47,0.01,2.64,0.84,3.52},
{0.6,0.06,0.02,0.01,0.011,0.0034,1.47,0,0.05,0.11,0.16},
{0.6,0.06,0.02,0.01,0.015,0.0034,1.47,0.01,0.07,1.42,1.5},
{2.33,0.05,0.01,0.004,0.004,0,3.19,0.01,0,0.03,0.04},
{2.33,0.05,0.01,0.004,0.004,0,3.19,0.01,0.03,0.93,0.97},
{1.49,0.08,0.02,0.005,0.006,0.0022,3.37,0.01,0.04,10.35,10.4},
{1.49,0.08,0.02,0.005,0.006,0.0022,3.37,0,0.2,0.64,0.84},
{1.71,0.04,0.01,0.003,0.008,0.0009,2.45,0.01,0.04,10.35,10.4},
{1.71,0.04,0.01,0.003,0.008,0.0009,2.45,0,0.03,3.14,3.17}};
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
_CommandPtr m_pCommand;
_variant_t RecordAffects;
HRESULT hr;
try
{
hr=m_pConnection.CreateInstance("ADODB.Connection");
hr=m_pRecordset.CreateInstance("ADODB.Recordset");
if(SUCCEEDED(hr))
{
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb;Persist Security Info=False",
"","",adModeUnknown);
m_pConnection->Execute("delete from Array",&RecordAffects,adCmdText);
m_pRecordset->Open("select * from Array",_variant_t((IDispatch*)m_pConnection,false),adOpenStatic,adLockOptimistic,adCmdText); //将数组的数据写入数据表
for(int i=0;i<9;i++)
{
m_pRecordset->AddNew();
for(int j=0;j<11;j++)
m_pRecordset->PutCollect(_variant_t((long)j),_variant_t(data[i][j]));
}
m_pRecordset->Update();
_variant_t vI=m_pRecordset->Fields->Count;
m_pRecordset->Close();
m_pRecordset=m_pConnection->Execute("select COUNT(*) from array",&RecordAffects,adCmdText);
_variant_t vIndex=(long)0;
_variant_t vCount= m_pRecordset->GetCollect(vIndex); m_pRecordset->Close();
CString message;
message.Format("共有:%d条记录!\r\n:共有:%d个字段!",vCount.lVal,vI.intVal);
AfxMessageBox(message);
}
}
catch(_com_error e)
{
CString errormsg;
errormsg.Format("连接数据库出错:\r\n%s",e.ErrorMessage);
AfxMessageBox(errormsg);
} if(m_pConnection->State)
{
m_pConnection->Close();
}
if(m_pRecordset->State)
{
m_pRecordset->Close();
}
CDialog::OnOK();
AfxMessageBox("Ok!!!!!!");
}
程序可以运行到最后一行:AfxMessageBox("Ok!!!!!!");
却出现如下错误:
弹出一个对话框:Unhandled exception in adoimport.exe ox000000000005:Access Violation.
问题说是在:c:...\vc98\include\comip.h
void _Release() throw()
{
if (m_pInterface != NULL) {
m_pInterface->Release();
}
}代码如下:void CAdoimportDlg::OnOK()
{
if(!AfxOleInit())
AfxMessageBox("初始化ADO出错!");
double data[9][11] =
{
{0.5,0.04,0.02,0.009,0.01,0.003,1.47,0.01,2.64,0.84,3.52},
{0.6,0.06,0.02,0.01,0.011,0.0034,1.47,0,0.05,0.11,0.16},
{0.6,0.06,0.02,0.01,0.015,0.0034,1.47,0.01,0.07,1.42,1.5},
{2.33,0.05,0.01,0.004,0.004,0,3.19,0.01,0,0.03,0.04},
{2.33,0.05,0.01,0.004,0.004,0,3.19,0.01,0.03,0.93,0.97},
{1.49,0.08,0.02,0.005,0.006,0.0022,3.37,0.01,0.04,10.35,10.4},
{1.49,0.08,0.02,0.005,0.006,0.0022,3.37,0,0.2,0.64,0.84},
{1.71,0.04,0.01,0.003,0.008,0.0009,2.45,0.01,0.04,10.35,10.4},
{1.71,0.04,0.01,0.003,0.008,0.0009,2.45,0,0.03,3.14,3.17}};
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
_CommandPtr m_pCommand;
_variant_t RecordAffects;
HRESULT hr;
try
{
hr=m_pConnection.CreateInstance("ADODB.Connection");
hr=m_pRecordset.CreateInstance("ADODB.Recordset");
if(SUCCEEDED(hr))
{
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb;Persist Security Info=False",
"","",adModeUnknown);
m_pConnection->Execute("delete from Array",&RecordAffects,adCmdText);
m_pRecordset->Open("select * from Array",_variant_t((IDispatch*)m_pConnection,false),adOpenStatic,adLockOptimistic,adCmdText); //将数组的数据写入数据表
for(int i=0;i<9;i++)
{
m_pRecordset->AddNew();
for(int j=0;j<11;j++)
m_pRecordset->PutCollect(_variant_t((long)j),_variant_t(data[i][j]));
}
m_pRecordset->Update();
_variant_t vI=m_pRecordset->Fields->Count;
m_pRecordset->Close();
m_pRecordset=m_pConnection->Execute("select COUNT(*) from array",&RecordAffects,adCmdText);
_variant_t vIndex=(long)0;
_variant_t vCount= m_pRecordset->GetCollect(vIndex); m_pRecordset->Close();
CString message;
message.Format("共有:%d条记录!\r\n:共有:%d个字段!",vCount.lVal,vI.intVal);
AfxMessageBox(message);
}
}
catch(_com_error e)
{
CString errormsg;
errormsg.Format("连接数据库出错:\r\n%s",e.ErrorMessage);
AfxMessageBox(errormsg);
} if(m_pConnection->State)
{
m_pConnection->Close();
}
if(m_pRecordset->State)
{
m_pRecordset->Close();
}
CDialog::OnOK();
AfxMessageBox("Ok!!!!!!");
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货