I am using a datareader to loop through 10 records in a table. As it loops I want to update a column but adding two columns.
Basically, I want to add 'countTotalByRun' and 'remainder' and update 'countTotalByRun' to that sum.
I am trying to do this, but it's failing on the cmd.ExecuteNonQuery saying a datareader is already open and needs to be closed first:
Dim objDR As SqlClient.SqlDataReader
Dim objCommand As SqlClient.SqlCommand
Dim ConnectionString As String = "Data Source=10.47.210.14,1433\S
Initial Catalog=eBanPress30;User Id=InvUser;Password=letmei
Dim objConnection As SqlClient.SqlConnection
Dim ssql As String
objConnection = New SqlClient.SqlConnection(Co
ssql = "SELECT * FROM partnumbers"
If objConnection.State <> ConnectionState.Open Then
objCommand = New SqlClient.SqlCommand(ssql,
objDR = objCommand.ExecuteReader(C
objCommand = Nothing
'Read all the rows
If objDR.HasRows Then
Dim cmd As SqlCommand
Dim strSQL As String
strSQL = "UPDATE partnumbers SET countTotalByRun ='" & ((objDR.Item("remainder"))
un"))) & "' WHERE customerPart = '" & (objDR.Item("customerPart"
)) & "'"
cmd = New SqlCommand(strSQL, objConnection)
objDR = Nothing
There has got to be an easier way to do this and I am all ears. Well, eyes anyway. Thanks for any help you can give me on this.