Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Datareader skips first record

Author  Topic 

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2005-09-09 : 12:52:36
'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()

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2005-09-09 : 13:11:48
I had two DR.Read()...just needed to delete the first one!
Go to Top of Page
   

- Advertisement -