下面是代码,在执行m_pRecordset->Delete(adAffectCurrent);的时候出错,望高手指教
try
{
         m_pRecordset->MoveFirst();
while(!m_pRecordset->adoEOF)
{
vuser=m_pRecordset->GetCollect("users");
vevents=m_pRecordset->GetCollect("events");
if(0==strcmp((LPCTSTR)(_bstr_t)vuser,Guser)&&0==strcmp((LPCTSTR)(_bstr_t)vevents,temp))
{
try
{
m_pRecordset->Delete(adAffectCurrent);
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage(),MB_OK,0);
}
break;
}
else
m_pRecordset->MoveNext();
}

}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage(),MB_OK,0);
}

解决方案 »

  1.   

    直接用sql语句来删,delete... from table
      

  2.   


     try  
            {
                m_pRecordset->->CursorLocation= adUseClient;
                m_pRecordset->->Open("DELETR ****** FROM ****** WHERE ******",
    m_pConnection.GetInterfacePtr(),  
    adOpenDynamic,
    adLockOptimistic,
    adCmdText);        }
      

  3.   

    http://blog.csdn.net/zyq5945/archive/2010/04/29/5541280.aspx
    什么错误,你可以用下面的代码查看具体的错误。
    //打印调用ADO控件时产生的详细错误信息
    void dump_com_error(_com_error &e)
    {
    CString ErrorStr;
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    ErrorStr.Format( "\n\tADO Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n\n",
    e.Error(), e.ErrorMessage(), (LPCTSTR)bstrSource, (LPCTSTR)bstrDescription );
    //在调试窗口中打印错误信息,在Release版中可用DBGView查看错误信息
    ::OutputDebugString((LPCTSTR)ErrorStr);
    #ifdef _DEBUG
    AfxMessageBox(ErrorStr, MB_OK | MB_ICONERROR);
    #endif
    }try
    {
    //你的ADO代码
            
    }
    catch(_com_error& e)
    {
    dump_com_error(e);
      

  4.   

    看看你操作数据库的用户角色有没有delete那个权限   你可以用查询分析器来试试你删除的语句是否正确
      

  5.   

    我也想用sql
    但也出错了
    m_pConnection->Execute("delete from beiwang where users=vuser and events=temp",&RecordsAffected,adCmdText);
    好像users=vuser这样不能用
      

  6.   


    vuser是变量,当然你这样不行,要这样:m_pConnection->Execute("delete from beiwang where users="+vuser+" and events=temp",&RecordsAffected,adCmdText);
      

  7.   

    我照你的写了,但出错了,error C2593: 'operator +' is ambiguous,请教高手,怎么办