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. Web Development
  3. ASP.NET
  4. Datareader skips first record

Datareader skips first record

Scheduled Pinned Locked Moved ASP.NET
databasehelpannouncement
2 Posts 1 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
    bubberz
    wrote on last edited by
    #1

    'Now Update WP_Cost_Codes Dim strWPPID As String strWPPID = "Select WP_PID from WP_GI WHERE [WBSN] = '" & strWBS & "'" Dim cmd2 As New SqlCommand(strWPPID, sCon1) Dim DR As SqlDataReader = cmd2.ExecuteReader() DR.Read() Dim fNextResult As Boolean = True Do Until Not fNextResult Do While (DR.Read()) Dim strWPID As String If IsDBNull(DR(0)) Then strWPID = String.Empty Else strWPID = DR(0) End If 'Now do the Update to WP_CC via WP_PID Dim strUWPCC As String strUWPCC = "Update WP_CC Set [Program Code] = '" & strNewPC & "', " strUWPCC &= "[Cost Account] = '" & strNewCA & "', [WP Number] = '" & strNewWN & "' " strUWPCC &= "WHERE WP_P_PID = '" & strWPID & "'" 'Now run the Insert Query Dim cmd3 As New SqlCommand(strUWPCC, sCon3) 'Try to open DB and execute Update Try cmd3.ExecuteNonQuery() Catch ex As Exception lblStatus.Text = "203 Error Updating WP_CC: " lblStatus.Text &= ex.Message Finally 'If Not (sCon3 Is Nothing) Then 'sCon3.Close() 'End If End Try Loop fNextResult = DR.NextResult() Loop DR.Close() DR = Nothing sCon3.Close() sCon1.Close()

    B 1 Reply Last reply
    0
    • B bubberz

      'Now Update WP_Cost_Codes Dim strWPPID As String strWPPID = "Select WP_PID from WP_GI WHERE [WBSN] = '" & strWBS & "'" Dim cmd2 As New SqlCommand(strWPPID, sCon1) Dim DR As SqlDataReader = cmd2.ExecuteReader() DR.Read() Dim fNextResult As Boolean = True Do Until Not fNextResult Do While (DR.Read()) Dim strWPID As String If IsDBNull(DR(0)) Then strWPID = String.Empty Else strWPID = DR(0) End If 'Now do the Update to WP_CC via WP_PID Dim strUWPCC As String strUWPCC = "Update WP_CC Set [Program Code] = '" & strNewPC & "', " strUWPCC &= "[Cost Account] = '" & strNewCA & "', [WP Number] = '" & strNewWN & "' " strUWPCC &= "WHERE WP_P_PID = '" & strWPID & "'" 'Now run the Insert Query Dim cmd3 As New SqlCommand(strUWPCC, sCon3) 'Try to open DB and execute Update Try cmd3.ExecuteNonQuery() Catch ex As Exception lblStatus.Text = "203 Error Updating WP_CC: " lblStatus.Text &= ex.Message Finally 'If Not (sCon3 Is Nothing) Then 'sCon3.Close() 'End If End Try Loop fNextResult = DR.NextResult() Loop DR.Close() DR = Nothing sCon3.Close() sCon1.Close()

      B Offline
      B Offline
      bubberz
      wrote on last edited by
      #2

      I had two DR.Read()...just needed to delete the first one!

      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