尝试更新或删除失败. [英] Attempt to Update or Delete failed.

查看:67
本文介绍了尝试更新或删除失败.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 AppWizard &创建了一个简单的 MFC ODBC 应用程序.我选择了将 MFC用作静态链接库(不作为DLL共享)的选项. &我开始为我的应用程序&当我尝试更新 pSet->Update(); 记录集时,出现错误消息"尝试更新或删除失败.".这是我的OnFileNew()函数代码:

I created a simple MFC ODBC application using the AppWizard & I chosed the option to use MFC as a statically linked library (Not shared as a DLL). & I started coding my app & when I try to Update pSet->Update(); the Recordset I got the error message "Attempt to Update or Delete failed.". This is my OnFileNew() function code:

void CDbOdbcView::OnFileNew()
{
    // TODO: Add your command handler code here
    // Get a pointer to the record set
    CDbOdbcSet* pSet = (CDbOdbcSet*)OnGetRecordset();
    // Make sure that any changes to the current record have been saved
    if (!pSet->IsBOF() && !pSet->IsEOF() && !pSet->IsDeleted() && pSet->CanUpdate())
    {
        pSet->Edit();
        if (!UpdateData())
            return;
        pSet->Update();
    }
    // Add the new record
    pSet->AddNew();
    // Set the ID in the new record
    pSet->m_RefAdresse = pSet->GetMaxID() + 1;
    // Save the new record
    pSet->Update();
    // Refresh the record set
    pSet->Requery();
    // Move to the new record
    pSet->MoveLast();
    // Update the form
    UpdateData(FALSE);
}



MFC作为静态链接库(不是作为DLL共享)是否会引起问题?
我被困完成我的项目. :confused:
请帮助我



Does the MFC as a statically linked library (Not shared as a DLL) cause the problem ?
I am stuck to complete my project. :confused:
Help me please

推荐答案

tomay3000写道:
tomay3000 wrote:

将MFC作为静态链接吗?库(未作为DLL共享)引起问题?

Does the MFC as a statically linked library (Not shared as a DLL) cause the problem ?



有一种明显的方法可以找出答案!但是我怀疑这会有所不同.您可能希望将代码放在try catch块中,然后查看引发的异常,以查看是否有任何其他信息可以帮助诊断问题.



There is one obvious way to find out! However I doubt that it would make any difference. You might like to put your code in a try catch block and then look at the exception that is thrown to see if there is any further information to help diagnose the problem.


最后我找到了原因,既没有使用 MFC作为静态链接库,也没有使用作为DLL共享解决了问题.问题出在函数pSet->GetMaxID()中,其定义是:
Finally I found the cause, neither the use of MFC as a statically linked library nor as shared as a DLL did the problem. The problem is in the function pSet->GetMaxID() which it''s defenition is:
long CDbOdbcSet::GetMaxID()
{
    // Is the recordset empty?
    if (IsBOF() && IsEOF())
        return 0;
    // Move to the last record
    MoveLast();
    // return the ID of this record
    return m_RefAdresse;
}


因此,我在pSet->GetMaxID();函数中先调用了pSet->AddNew();,然后又调用了MoveLast();,所以pSet->AddNew();在调用MoveLast();&之后没有任何作用(已消失). pSet->Update();将引发异常;)
感谢您尝试提供帮助的任何人;)


So I called the pSet->AddNew(); then MoveLast(); inside pSet->GetMaxID(); function, so the pSet->AddNew(); has no effect (has gone) after the call of MoveLast(); & pSet->Update(); will throw an exception ;)
Thanks for anybody who tried to help ;)


这篇关于尝试更新或删除失败.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆