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. .NET (Core and Framework)
  4. DataReader.Read not working? [Solved]

DataReader.Read not working? [Solved]

Scheduled Pinned Locked Moved .NET (Core and Framework)
databasequestionlounge
3 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.
  • B Offline
    B Offline
    B rad A
    wrote on last edited by
    #1

    I am using the datareader to read through a foxpro table and when there are multiple records in the table it will only read the first one and then drop out of the loop. Any ideas on why it is doing this?

    If DR.HasRows Then
    While DR.Read()
    random code here...
    uploadDate = sql statement...
    uplDate = New OleDb.OleDbCommand(uploadDate, objConnection)
    DR = uplDate.ExecuteReader
    DR.Read()
    End While
    End If

    modified on Monday, April 12, 2010 3:10 PM

    P J 2 Replies Last reply
    0
    • B B rad A

      I am using the datareader to read through a foxpro table and when there are multiple records in the table it will only read the first one and then drop out of the loop. Any ideas on why it is doing this?

      If DR.HasRows Then
      While DR.Read()
      random code here...
      uploadDate = sql statement...
      uplDate = New OleDb.OleDbCommand(uploadDate, objConnection)
      DR = uplDate.ExecuteReader
      DR.Read()
      End While
      End If

      modified on Monday, April 12, 2010 3:10 PM

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You're reusing the same reader to do something different which executes on the same connection. That's why it's dropping out of the loop. Change this to execute the second reader on a different connection if it's doing something with the data from the first query.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      1 Reply Last reply
      0
      • B B rad A

        I am using the datareader to read through a foxpro table and when there are multiple records in the table it will only read the first one and then drop out of the loop. Any ideas on why it is doing this?

        If DR.HasRows Then
        While DR.Read()
        random code here...
        uploadDate = sql statement...
        uplDate = New OleDb.OleDbCommand(uploadDate, objConnection)
        DR = uplDate.ExecuteReader
        DR.Read()
        End While
        End If

        modified on Monday, April 12, 2010 3:10 PM

        J Offline
        J Offline
        jaypatel512
        wrote on last edited by
        #3

        It seems that you need to use two different Data Reader. DR is fine for the external while loop. But inside the while loop you are re-updating its value which is leading to the problem.. Try using another instance of the datareader, and it would work completely fine.

        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