MFC CRecordset Delete gives a debug assertion failed mesage in runtime.

Posted on 2004-11-05
Last Modified: 2013-11-20
I am writeing a program in Visual C++ (Console based with MFC support) for database. I try to delete recode from the *.mdb file but it gives me a dubeg assertion error during runtime. I can open the record. I tried to debug and found that Assert(FALSE) happens in SetFieldNull(....) function inside dbcore.cpp file. After program fails, I can see the successful deletion in the *.mdb file. Can anyone help me to solve this debug Assert message.
Here is the code that I wrote in MFC/Visual C++.

CDatabase db;
CString strConnection = _T("Driver=Microsoft Access Driver (*.mdb);"
db.OpenEx(_T(strConnection), CDatabase::noOdbcDialog);
CRecordset rs(&db);
rs.Open(CRecordset::dynaset,_T("SELECT * FROM Table1")); //, CRecordset::none);

if(rs.IsEOF() || !rs.CanUpdate() || !rs.CanTransact())
       return nRetCode;

CString varValue;      
short nFields = rs.GetODBCFieldCount();

         for(short index = 0; index < nFields; index++)
      rs.GetFieldValue(index, varValue);                          
Question by:jayvat27
    LVL 19

    Expert Comment

    if (m_nFields <= 0)
          ASSERT(FALSE); // <----

    I take it that is what you are referring to as the assertion point.  

    If not, you could read


    Author Comment

    I could not undersatand what you trying to say.. Can you explain it in detail. Do you mean that I have to take out the ASSERT(FALSE) code line from the dbcore.cpp file? I also read the link that does not relate to my problem. I am getting Assertion falilure when I try to delete record.
    Can you please help me more on it..
    Thanks in advance.
    LVL 19

    Expert Comment

    Jayvat27, sorry for the delay in getting back to you.  What I was saying is the the line that is asserting is being caused by the

     if (m_nFields <= 0)

    evaluating to true.  So if you look in the dbcore.cpp file, see what m_nFields is, then see what in your code could possibly cause that to be the case.  That will give you the answer.
    LVL 1

    Accepted Solution

        The problem which you are reffering to is not because of deletion. After deleting the record, you are calling rs.MoveNext(). After deleting the last record if you call MoveNext the application gives assertion. Please try to check for EOF condition before calling MoveNext.


    I think this will solve your problem.


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
    This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now