[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2004-11-05
Medium Priority
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
  • 2
LVL 19

Expert Comment

ID: 12514502
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 http://www.it-faq.pl/mskb/160/074.HTM


Author Comment

ID: 12528789
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

ID: 12686537
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.

Accepted Solution

suryaxchange earned 2000 total points
ID: 12837804
    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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month19 days, 6 hours left to enroll

834 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