recordSetPtr->Delete 的问题

seadistant 2010-02-23 04:58:11

try{
strSqlSoundFileTable.Format("SELECT * FROM SoundFileTable WHERE SoundFileName='%s'",strSoundFileName);
_RecordsetPtr recordSetPtr=ExcuteSql(strSqlSoundFileTable);

if (!(recordSetPtr->BOF))
{
recordSetPtr->MoveFirst();
///此文件名已在声音库中存在了那么提示,让用户选择(覆盖,不覆盖(使用以前的),取消添加
///覆盖,删除
recordSetPtr->Delete(adAffectCurrent);
//recordSetPtr->Update();
}
}catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}


总是报错,并且 错误无法被捉到,(错误就在recordSetPtr->Delete(adAffectCurrent);这一句上)
其它功能都正常(如添加,查询,更改)
请高手帮助

...全文
235 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
seadistant 2010-02-23
  • 打赏
  • 举报
回复
楼上的好像没有什么用,错误类型不是_com_error,所以捉不到,
BombZhang 2010-02-23
  • 打赏
  • 举报
回复
给你个抓数据库错误的catch:

CString GetProviderError(_ConnectionPtr pConnection)
{
CString sErrors;
if(pConnection != NULL)
{
ADODB::ErrorsPtr ptrErrors = pConnection->Errors;
long lCount = ptrErrors->Count;
ADODB::ErrorPtr ptrError = NULL;
CString sError;
for(long n = 0; n < lCount; n++)
{
ptrError = ptrErrors->GetItem(n);
sError.Format(
_T("%s\nState: %s, Native: %d, Source: %s"),
(LPCTSTR)ptrError->Description,
(LPCTSTR)ptrError->SQLState,
ptrError->NativeError,
(LPCTSTR)ptrError->Source
);
sErrors += sError + TEXT("\n\n");
}
}

if(!sErrors.IsEmpty())
sErrors = sErrors.Left(sErrors.GetLength()-2);

return sErrors;
}

_ConnectionPtr pConnection
catch(const _com_error& e)
{
CString sBuff = GetProviderError(pConnection);
if(sBuff.IsEmpty())
{
sBuff=GetComError(e);
}
AfxMessageBox(sBuff);
}

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧