Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem in CRecordSet

Problem in CRecordSet

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpdatabase
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    M_Menon
    wrote on last edited by
    #1

    Hi friends I am really new with Visual C++. I am using MS Access for DB. I am trying to take data from a table and pass it to my recordset rs. I am trying to check if i have received any records for my statement. my code is rs is CRecordSet. While(!rs.IsEof) {} Here even when my DB has returned no data it goes inside the While statement. I believe this is the standard statement to check if you DB has returned zero rows or no data, or whatsoever. But even when i get Data or i dont still it executes statements inside While. Any help would be appreciated. Thanks Cheers Menon

    P 1 Reply Last reply
    0
    • M M_Menon

      Hi friends I am really new with Visual C++. I am using MS Access for DB. I am trying to take data from a table and pass it to my recordset rs. I am trying to check if i have received any records for my statement. my code is rs is CRecordSet. While(!rs.IsEof) {} Here even when my DB has returned no data it goes inside the While statement. I believe this is the standard statement to check if you DB has returned zero rows or no data, or whatsoever. But even when i get Data or i dont still it executes statements inside While. Any help would be appreciated. Thanks Cheers Menon

      P Offline
      P Offline
      panthal
      wrote on last edited by
      #2

      use this code , while(!recset.IsEOF()) // Do until EOF { }

      M 1 Reply Last reply
      0
      • P panthal

        use this code , while(!recset.IsEOF()) // Do until EOF { }

        M Offline
        M Offline
        M_Menon
        wrote on last edited by
        #3

        hi there I am using while(rs.IsEOF()) {} but still...it goes inside the while loop. thanks Cheers Menon

        D 1 Reply Last reply
        0
        • M M_Menon

          hi there I am using while(rs.IsEOF()) {} but still...it goes inside the while loop. thanks Cheers Menon

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          mady1380 wrote:

          while(rs.IsEOF()) {} but still...it goes inside the while loop.

          Because rs.IsEOF() is evaluating to true, thus the while loop is executing. Why don't you copy/paste the exact code you are using rather than mangle it all up by retyping it?


          "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          M 1 Reply Last reply
          0
          • D David Crow

            mady1380 wrote:

            while(rs.IsEOF()) {} but still...it goes inside the while loop.

            Because rs.IsEOF() is evaluating to true, thus the while loop is executing. Why don't you copy/paste the exact code you are using rather than mangle it all up by retyping it?


            "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            M Offline
            M Offline
            M_Menon
            wrote on last edited by
            #5

            Hi Friends i am Sorry for not writing the complete code. Here is my code CRecordset rs( &db ); tmp.Format( _T("SELECT MAX(Polhsh_ID) FROM Polhsh WHERE Installation_ID = %d"), Installation_ID); db.ExecuteSQL( tmp ); rs.Open( CRecordset::forwardOnly, tmp, CRecordset::readOnly ); while( !rs.IsEOF()) { CDBVariant ID; rs.GetFieldValue( (short)0, ID ); m_Polhsh_ID= ID.m_lVal; Now my problem is even though my Table Polhsh is empty and has no records, it is going inside the while loop. And henceforth i get an error as the line rs.GetFieldValue( (short)0, ID ); Thanks Cheers Menon

            D 1 Reply Last reply
            0
            • M M_Menon

              Hi Friends i am Sorry for not writing the complete code. Here is my code CRecordset rs( &db ); tmp.Format( _T("SELECT MAX(Polhsh_ID) FROM Polhsh WHERE Installation_ID = %d"), Installation_ID); db.ExecuteSQL( tmp ); rs.Open( CRecordset::forwardOnly, tmp, CRecordset::readOnly ); while( !rs.IsEOF()) { CDBVariant ID; rs.GetFieldValue( (short)0, ID ); m_Polhsh_ID= ID.m_lVal; Now my problem is even though my Table Polhsh is empty and has no records, it is going inside the while loop. And henceforth i get an error as the line rs.GetFieldValue( (short)0, ID ); Thanks Cheers Menon

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              mady1380 wrote:

              db.ExecuteSQL( tmp );

              This statement is not necessary.

              mady1380 wrote:

              Now my problem is even though my Table Polhsh is empty and has no records...

              How are you verifying this?

              mady1380 wrote:

              And henceforth i get an error as the line rs.GetFieldValue( (short)0, ID );

              What error?


              "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              M 1 Reply Last reply
              0
              • D David Crow

                mady1380 wrote:

                db.ExecuteSQL( tmp );

                This statement is not necessary.

                mady1380 wrote:

                Now my problem is even though my Table Polhsh is empty and has no records...

                How are you verifying this?

                mady1380 wrote:

                And henceforth i get an error as the line rs.GetFieldValue( (short)0, ID );

                What error?


                "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                M Offline
                M Offline
                M_Menon
                wrote on last edited by
                #7

                The Error is First-chance exception at 0x77e55e02 in PigMaster-S.exe: Microsoft C++ exception: CDBException @ 0x0012dc74. The Verification Statement is supposed to be while( !rs.IsEOF()) //VERIFY { I hope the above statement is used to verify if it has data or not? Thanks Cheers Menon

                D 1 Reply Last reply
                0
                • M M_Menon

                  The Error is First-chance exception at 0x77e55e02 in PigMaster-S.exe: Microsoft C++ exception: CDBException @ 0x0012dc74. The Verification Statement is supposed to be while( !rs.IsEOF()) //VERIFY { I hope the above statement is used to verify if it has data or not? Thanks Cheers Menon

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  mady1380 wrote:

                  First-chance exception at 0x77e55e02 in PigMaster-S.exe: Microsoft C++ exception: CDBException @ 0x0012dc74.

                  Step into the GetFieldValue() call to find what statement is throwing the exception.

                  mady1380 wrote:

                  The Verification Statement is supposed to be while( !rs.IsEOF()) //VERIFY { I hope the above statement is used to verify if it has data or not?

                  Why not issue the same SQL statement within Access to verify whether it actually has any records or not?


                  "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  M 1 Reply Last reply
                  0
                  • D David Crow

                    mady1380 wrote:

                    First-chance exception at 0x77e55e02 in PigMaster-S.exe: Microsoft C++ exception: CDBException @ 0x0012dc74.

                    Step into the GetFieldValue() call to find what statement is throwing the exception.

                    mady1380 wrote:

                    The Verification Statement is supposed to be while( !rs.IsEOF()) //VERIFY { I hope the above statement is used to verify if it has data or not?

                    Why not issue the same SQL statement within Access to verify whether it actually has any records or not?


                    "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    M Offline
                    M Offline
                    M_Menon
                    wrote on last edited by
                    #9

                    Hi David I have the seen the table. And there are absolutely no records in the table. And that is confirm. My only problem is. Why is it going inside the WHILE loop inspite of not having any records in the table? Is while( !rs.IsEOF()) //VERIFY { the proper statement to make check if the table is empty or not. Thanks Cheers Menon

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups