简单有关问题,就几句代码大家帮小弟我看一下
简单问题,就几句代码大家帮我看一下
用ADO向ACCESS数据库插入数据,出现中断,错误是“在某内存处有未处理的异常:Mircosoft C++异常:内存位置0x001cee14处的_com_error”一下是代码:
try{
db.AccessData();//打开数据库
CString strSql=_T("select * from login where serverIP="+ip);
db.m_pRecordset=db.m_pConnection->Execute((_bstr_t)strSql,NULL,adCmdText);//确认记录是否存在
if(db.m_pRecordset->adoBOF) //如果记录不存在则插入记录
{
db.m_pRecordset->AddNew();//这一句出现中断
db.m_pRecordset->PutCollect("serverIP",_variant_t(ip));
db.m_pRecordset->PutCollect("dataName", _variant_t(dataName));
db.m_pRecordset->PutCollect("loginName", _variant_t(loginName));
db.m_pRecordset->Update();
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage())
}
然后我跟踪调试,就是db.m_pRecordset->AddNew();这一句报错,各位大侠帮帮忙,内牛满面啊!
------解决方案--------------------
改为以下试试看:
db.m_pRecordset->Open(_ (_bstr_t)strSql, db.m_pConnection->GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
用ADO向ACCESS数据库插入数据,出现中断,错误是“在某内存处有未处理的异常:Mircosoft C++异常:内存位置0x001cee14处的_com_error”一下是代码:
try{
db.AccessData();//打开数据库
CString strSql=_T("select * from login where serverIP="+ip);
db.m_pRecordset=db.m_pConnection->Execute((_bstr_t)strSql,NULL,adCmdText);//确认记录是否存在
if(db.m_pRecordset->adoBOF) //如果记录不存在则插入记录
{
db.m_pRecordset->AddNew();//这一句出现中断
db.m_pRecordset->PutCollect("serverIP",_variant_t(ip));
db.m_pRecordset->PutCollect("dataName", _variant_t(dataName));
db.m_pRecordset->PutCollect("loginName", _variant_t(loginName));
db.m_pRecordset->Update();
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage())
}
然后我跟踪调试,就是db.m_pRecordset->AddNew();这一句报错,各位大侠帮帮忙,内牛满面啊!
------解决方案--------------------
改为以下试试看:
db.m_pRecordset->Open(_ (_bstr_t)strSql, db.m_pConnection->GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);