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

Hi,
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);"
                  "Dbq=db1.mdb;Uid=;Pwd=;");    
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);                          
      cout<<LPCTSTR(varValue)<<endl;            
        }
      cout<<endl<<endl;
      db.BeginTrans();      
      rs.Delete();
      
      db.CommitTrans();
      rs.MoveNext();                        
      rs.Close();
      db.Close();      
Thanks.
jayvat27.
jayvat27Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mrwad99Commented:
if (m_nFields <= 0)
{
      ASSERT(FALSE); // <----
      return;
}

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

HTH
0
jayvat27Author Commented:
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.
Jayvat27
0
mrwad99Commented:
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.
0
Surya BobbadhiTechnical ConsultantCommented:
Hi,
    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.

if(!rs.IsEOF())
   rs.MoveNext().

I think this will solve your problem.

Surya.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.