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. Visual Basic
  4. RecordSets In ADO for VB6

RecordSets In ADO for VB6

Scheduled Pinned Locked Moved Visual Basic
helpdatabasedebugging
6 Posts 2 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.
  • R Offline
    R Offline
    rradhay
    wrote on last edited by
    #1

    I am having a problem in vb 6 in trying to access the content of recordsets which store the results of a query. When I try to pull the value out of the recordset as in dim value = rs!key, I get an error saying that the recordset is empty (I test the BOF and EOF and I get both to be true for the rs), - (the code crashes and gives this error at rs.MoveFirst), however when i click on debug and go into the code, the rs fills and the code continues to the end successfully. I am also getting this problem in a different context where in trying to insert records into a table, recordsets are updating and reading too slowly so old values are being inserted into tables generating errors. I only get these errors when I run the code, but If i step through I get NO errors! Please help!:((

    A R 2 Replies Last reply
    0
    • R rradhay

      I am having a problem in vb 6 in trying to access the content of recordsets which store the results of a query. When I try to pull the value out of the recordset as in dim value = rs!key, I get an error saying that the recordset is empty (I test the BOF and EOF and I get both to be true for the rs), - (the code crashes and gives this error at rs.MoveFirst), however when i click on debug and go into the code, the rs fills and the code continues to the end successfully. I am also getting this problem in a different context where in trying to insert records into a table, recordsets are updating and reading too slowly so old values are being inserted into tables generating errors. I only get these errors when I run the code, but If i step through I get NO errors! Please help!:((

      A Offline
      A Offline
      Andy H
      wrote on last edited by
      #2

      If rs.BOF AND rs.EOF are both true then the rs is either nothing or empty. In which case don't let your code use the rs. Sounds like the underlying db has just been populated and you are attempting to get records from it before the db has finished updating itself i.e. after data has been sent to it. Are you using Access by any chance? Try putting a wait in your code after the db has been populated.

      A R 2 Replies Last reply
      0
      • A Andy H

        If rs.BOF AND rs.EOF are both true then the rs is either nothing or empty. In which case don't let your code use the rs. Sounds like the underlying db has just been populated and you are attempting to get records from it before the db has finished updating itself i.e. after data has been sent to it. Are you using Access by any chance? Try putting a wait in your code after the db has been populated.

        A Offline
        A Offline
        Andy H
        wrote on last edited by
        #3

        Take a look at this URL for your solution: http://www.blackbeltvb.com/index.htm?free.htm

        1 Reply Last reply
        0
        • A Andy H

          If rs.BOF AND rs.EOF are both true then the rs is either nothing or empty. In which case don't let your code use the rs. Sounds like the underlying db has just been populated and you are attempting to get records from it before the db has finished updating itself i.e. after data has been sent to it. Are you using Access by any chance? Try putting a wait in your code after the db has been populated.

          R Offline
          R Offline
          rradhay
          wrote on last edited by
          #4

          Yes I am using an Access Db. Could you give me an example of using the wait code for recordsets or after the db has been populated? I was looking on the net and could not find anything! Thanks so much for your help! Looking forward to your response!

          A 1 Reply Last reply
          0
          • R rradhay

            Yes I am using an Access Db. Could you give me an example of using the wait code for recordsets or after the db has been populated? I was looking on the net and could not find anything! Thanks so much for your help! Looking forward to your response!

            A Offline
            A Offline
            Andy H
            wrote on last edited by
            #5

            The correct solution to your problem would be to open an asyncronous connection and then when you have written your data to the db wait until the connection has finished executing the SQL command. Use the ADO const dbRunAsync when opening the connection to get an asyncronous connection. Then write the data to the db, and wait by using a loop such as: Do While Con.StillExecuting ... Loop When the loop exits the db has been updated and you can then retrieve the required data. HTH

            1 Reply Last reply
            0
            • R rradhay

              I am having a problem in vb 6 in trying to access the content of recordsets which store the results of a query. When I try to pull the value out of the recordset as in dim value = rs!key, I get an error saying that the recordset is empty (I test the BOF and EOF and I get both to be true for the rs), - (the code crashes and gives this error at rs.MoveFirst), however when i click on debug and go into the code, the rs fills and the code continues to the end successfully. I am also getting this problem in a different context where in trying to insert records into a table, recordsets are updating and reading too slowly so old values are being inserted into tables generating errors. I only get these errors when I run the code, but If i step through I get NO errors! Please help!:((

              R Offline
              R Offline
              rradhay
              wrote on last edited by
              #6

              I am attempting to connect to an Access Database with not much data and am using MDAC version 2.70.7713.4...I have worked around the problem. I noticed that the record I was querying for and then using movefirst to retrieve, was added immediately prior to performing the query for the value associated with the record added. Before: 'If record did not exist then add record Dim rs As New ADODB.Recordset SQL = "TableName" rs.Open SQL, dbMasterConn, adOpenKeyset, adLockOptimistic, adCmdTable rs.Addnew rs!code = varCode rs.Update 'Following this a rs was filled for generic instances where record did or did not exist for the record just added. Record was only added if it did not exist but the code is needed regardless of whether record did or did not exist Dim rs As New ADODB.RecordSet rs.Source = "SELECT code FROM TableName where condition" rs.CursorType = adOpenForwardOnly rs.ActiveConnection = dbMaster rs.Open rs.MoveFirst <--it stuck here CodeNeded = rs!code After changes: 'If record did not exist then Dim rs As New ADODB.Recordset rs.ActiveConnection = MasterDb SQL = "TableName" rs.Open SQL, , adOpenKeyset, adLockOptimistic, adCmdTable rs.Addnew rs!code = varCode rs.Update CodeNeeded = varCode else(if record already exists) Dim rs As New ADODB.RecordSet rs.Source = "SELECT code FROM TableName where condition" rs.CursorType = adOpenForwardOnly rs.ActiveConnection = dbMaster rs.Open rs.MoveFirst <--no longer stuck here and ran. CodeNeded = rs!code A very good detailed link that helped with making connections, creating recordsets, reading and adding values to recordsets etc for both DAO and ADO was: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacc2k/html/acchap2.asp

              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