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. quick question about recordsets, ADO

quick question about recordsets, ADO

Scheduled Pinned Locked Moved C / C++ / MFC
databasetutorialquestion
14 Posts 7 Posters 2 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.
  • N ns

    I get back from a query the result that the number of records found is 0. Immediately after I process commands with this rs. It crashes. So I want to put in an exit like if(rs has zero records) { do this return } However I dont know how to state 'rs has zero records'....in ADO. I dont see an isEmpty type function in the docs. I am using ADO. Thanks, ns

    R Offline
    R Offline
    Ravi Bhavnani
    wrote on last edited by
    #2

    GetRows() perhaps? (I don't know ADO). /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

    1 Reply Last reply
    0
    • N ns

      I get back from a query the result that the number of records found is 0. Immediately after I process commands with this rs. It crashes. So I want to put in an exit like if(rs has zero records) { do this return } However I dont know how to state 'rs has zero records'....in ADO. I dont see an isEmpty type function in the docs. I am using ADO. Thanks, ns

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #3

      Or maybe you could check its EOF property? (Sorry, just guessing.) /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

      1 Reply Last reply
      0
      • N ns

        I get back from a query the result that the number of records found is 0. Immediately after I process commands with this rs. It crashes. So I want to put in an exit like if(rs has zero records) { do this return } However I dont know how to state 'rs has zero records'....in ADO. I dont see an isEmpty type function in the docs. I am using ADO. Thanks, ns

        B Offline
        B Offline
        Blade DMS
        wrote on last edited by
        #4

        When the Recordset is empty, both the BOF and EOF flags are set, so...

        if (rs.IsBOF() && rs.IsEOF())
        {
        do this
        return
        }

        should be what you want.... Blade[DMS]

        N 1 Reply Last reply
        0
        • B Blade DMS

          When the Recordset is empty, both the BOF and EOF flags are set, so...

          if (rs.IsBOF() && rs.IsEOF())
          {
          do this
          return
          }

          should be what you want.... Blade[DMS]

          N Offline
          N Offline
          ns
          wrote on last edited by
          #5

          This didnt pass the compiler: IsEOF is a dao thing, EOF is not an ADO thing either. getting close though....:)

          	/\*	if((m\_photoDb.m\_pRecordsetPhoto.BOF = TRUE) &&                       
                                ( m\_photoDb.m\_pRecordsetPhoto.EOF = TRUE))
          		{
          			AfxMessageBox ("empty rs");
          			return;
          		}\*/
          

          Thanks for the responses, ns OOPS! I think I need ->EOF not .EOF....I'm trying it now. DArn! That wasnt it.

          R B 2 Replies Last reply
          0
          • N ns

            This didnt pass the compiler: IsEOF is a dao thing, EOF is not an ADO thing either. getting close though....:)

            	/\*	if((m\_photoDb.m\_pRecordsetPhoto.BOF = TRUE) &&                       
                                  ( m\_photoDb.m\_pRecordsetPhoto.EOF = TRUE))
            		{
            			AfxMessageBox ("empty rs");
            			return;
            		}\*/
            

            Thanks for the responses, ns OOPS! I think I need ->EOF not .EOF....I'm trying it now. DArn! That wasnt it.

            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #6

            == not = :omg: /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

            N 1 Reply Last reply
            0
            • R Ravi Bhavnani

              == not = :omg: /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

              N Offline
              N Offline
              ns
              wrote on last edited by
              #7

              guess what - I tried that too....I really did.

              Compiling...
              Train1View.cpp
              C:\Train1View.cpp(2473) : error C2059: syntax error : '('
              C:\Train1View.cpp(2474) : error C2143: syntax error : missing ';' before '{'
              C:\Train1View.cpp(2475) : error C2039: 'AfxMessageBox' : is not a member of '_Recordset'
              c:\trainer\a_tr series\tr8b\release\msado15.tlh(1696) : see declaration of '_Recordset'
              C:\Train1View.cpp(2488) : error C2039: 'm_photoDb' : is not a member of '_Recordset'
              c:\trainer\a_tr series\tr8b\release\msado15.tlh(1696) : see declaration of '_Recordset'
              C:\Train1View.cpp(2488) : error C2039: 'GetPhotoBuffer' : is not a member of '_Recordset'
              c:\trainer\a_tr series\tr8b\release\msado15.tlh(1696) : see declaration of '_Recordset'
              Error executing cl.exe.

              R 1 Reply Last reply
              0
              • N ns

                This didnt pass the compiler: IsEOF is a dao thing, EOF is not an ADO thing either. getting close though....:)

                	/\*	if((m\_photoDb.m\_pRecordsetPhoto.BOF = TRUE) &&                       
                                      ( m\_photoDb.m\_pRecordsetPhoto.EOF = TRUE))
                		{
                			AfxMessageBox ("empty rs");
                			return;
                		}\*/
                

                Thanks for the responses, ns OOPS! I think I need ->EOF not .EOF....I'm trying it now. DArn! That wasnt it.

                B Offline
                B Offline
                Blade DMS
                wrote on last edited by
                #8

                I think it depends how you import the ADO code, but in my version "EOF" is renamed to "adoEOF" because of the conflict with the C EOF define for end of file returned by fgetc etc... try...

                if ((m_photoDb.m_pRecordsetPhoto->BOF == TRUE)
                && (m_photoDb.m_pRecordsetPhoto->adoEOF == TRUE))
                {
                AfxMessageBox ("empty rs");
                return;
                }

                Blade[DMS]

                N R 2 Replies Last reply
                0
                • N ns

                  guess what - I tried that too....I really did.

                  Compiling...
                  Train1View.cpp
                  C:\Train1View.cpp(2473) : error C2059: syntax error : '('
                  C:\Train1View.cpp(2474) : error C2143: syntax error : missing ';' before '{'
                  C:\Train1View.cpp(2475) : error C2039: 'AfxMessageBox' : is not a member of '_Recordset'
                  c:\trainer\a_tr series\tr8b\release\msado15.tlh(1696) : see declaration of '_Recordset'
                  C:\Train1View.cpp(2488) : error C2039: 'm_photoDb' : is not a member of '_Recordset'
                  c:\trainer\a_tr series\tr8b\release\msado15.tlh(1696) : see declaration of '_Recordset'
                  C:\Train1View.cpp(2488) : error C2039: 'GetPhotoBuffer' : is not a member of '_Recordset'
                  c:\trainer\a_tr series\tr8b\release\msado15.tlh(1696) : see declaration of '_Recordset'
                  Error executing cl.exe.

                  R Offline
                  R Offline
                  Ravi Bhavnani
                  wrote on last edited by
                  #9

                  Mail me Train1View.cpp. Looks like you got a misplaced ->. /ravi Let's put "civil" back in "civilization" http://www.ravib.com ravib@ravib.com

                  1 Reply Last reply
                  0
                  • B Blade DMS

                    I think it depends how you import the ADO code, but in my version "EOF" is renamed to "adoEOF" because of the conflict with the C EOF define for end of file returned by fgetc etc... try...

                    if ((m_photoDb.m_pRecordsetPhoto->BOF == TRUE)
                    && (m_photoDb.m_pRecordsetPhoto->adoEOF == TRUE))
                    {
                    AfxMessageBox ("empty rs");
                    return;
                    }

                    Blade[DMS]

                    N Offline
                    N Offline
                    ns
                    wrote on last edited by
                    #10

                    I checked for the recordcount and used that instead. SO the original mystery is unsolved, but I have a workaround.. :)

                    R 1 Reply Last reply
                    0
                    • N ns

                      I checked for the recordcount and used that instead. SO the original mystery is unsolved, but I have a workaround.. :)

                      R Offline
                      R Offline
                      Rashid Thadha
                      wrote on last edited by
                      #11

                      I would be careful on how you use the recordcount method. I think this is just a water mark of the number of records you have iterated through. The count that it returns is only correct if you have iterated through the whole recordset. You have to use EOF and BOF to work out if you have any records. When you Import the ADO object you usually rename EOF to what ever you want

                      1 Reply Last reply
                      0
                      • B Blade DMS

                        I think it depends how you import the ADO code, but in my version "EOF" is renamed to "adoEOF" because of the conflict with the C EOF define for end of file returned by fgetc etc... try...

                        if ((m_photoDb.m_pRecordsetPhoto->BOF == TRUE)
                        && (m_photoDb.m_pRecordsetPhoto->adoEOF == TRUE))
                        {
                        AfxMessageBox ("empty rs");
                        return;
                        }

                        Blade[DMS]

                        R Offline
                        R Offline
                        Ranjan Banerji
                        wrote on last edited by
                        #12

                        If you are using namespaces then you may need to say something like ADODB::EOF or ADODB::adEOF etc. Check the .tlh file and see what the constant is.

                        1 Reply Last reply
                        0
                        • N ns

                          I get back from a query the result that the number of records found is 0. Immediately after I process commands with this rs. It crashes. So I want to put in an exit like if(rs has zero records) { do this return } However I dont know how to state 'rs has zero records'....in ADO. I dont see an isEmpty type function in the docs. I am using ADO. Thanks, ns

                          M Offline
                          M Offline
                          Mazdak
                          wrote on last edited by
                          #13

                          There is other way for it too.First Execute this query: select count(*) from yourtable It always return 1 record and its number of rows in table(at least it return 0 in that record),so you can find out how many records are in the table. Mazy **"If I go crazy then will you still Call me Superman If I’m alive and well, will you be There holding my hand I’ll keep you by my side with My superhuman might Kryptonite"**Kryptonite-3 Doors Down

                          J 1 Reply Last reply
                          0
                          • M Mazdak

                            There is other way for it too.First Execute this query: select count(*) from yourtable It always return 1 record and its number of rows in table(at least it return 0 in that record),so you can find out how many records are in the table. Mazy **"If I go crazy then will you still Call me Superman If I’m alive and well, will you be There holding my hand I’ll keep you by my side with My superhuman might Kryptonite"**Kryptonite-3 Doors Down

                            J Offline
                            J Offline
                            Jon Hulatt
                            wrote on last edited by
                            #14

                            that is hideously inefficent. i'd just get the EOF thing working. STL is a religeon. Enquiries to Reverend Christian Graus

                            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