Datareader skips first record
-
'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()
-
'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()