Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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);
}


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
Posted
Updated 25-Nov-10 5:21am
v2

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


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.
 
Share this answer
 
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:
C#
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;
}

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 ;)
 
Share this answer
 
v3
Comments
Richard MacCutchan 26-Nov-10 7:15am    
Please mark one of the suggestions as "Answer" so your query goes off the unanswered list? Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900