G
Guest
Hello,
How can I use an ExecuteNonQuery within the loop of a datareader?
My code is as follows:
Dim cmdToProcess As New SqlClient.SqlCommand
Dim rdToProcess As SqlClient.SqlDataReader
With cmdToProcess
.CommandText = " SELECT * FROM tblDetails "
.Connection = cn
End With
rdToProcess = cmdToProcess .ExecuteReader
Select Case rdToProcess
Case True
Do
'here I want to add or update data
Dim cmdToChange As New SqlClient.SqlCommand
With cmdToChange
.CommandText = "INSERT INTO tblNew(AD_Action) VALUES (@Action)"
.Parameters.AddWithValue("@Action", rdToProcess("DE_Number"))
.Connection = cn
End With
cmdToChange.ExecuteNonQuery
Loop until not rdProcess.Read
End Select
At "cmdNieuweCafetariaActiedetail.ExecuteNonQuery", I get the message that I
have to close the first datareader in order to
execute, but then my code cannot proceed because rdToProcess("DE_Number")
can no longer be read.
How can I solve this?
Many thanks and greetings for your help,
Michel
How can I use an ExecuteNonQuery within the loop of a datareader?
My code is as follows:
Dim cmdToProcess As New SqlClient.SqlCommand
Dim rdToProcess As SqlClient.SqlDataReader
With cmdToProcess
.CommandText = " SELECT * FROM tblDetails "
.Connection = cn
End With
rdToProcess = cmdToProcess .ExecuteReader
Select Case rdToProcess
Case True
Do
'here I want to add or update data
Dim cmdToChange As New SqlClient.SqlCommand
With cmdToChange
.CommandText = "INSERT INTO tblNew(AD_Action) VALUES (@Action)"
.Parameters.AddWithValue("@Action", rdToProcess("DE_Number"))
.Connection = cn
End With
cmdToChange.ExecuteNonQuery
Loop until not rdProcess.Read
End Select
At "cmdNieuweCafetariaActiedetail.ExecuteNonQuery", I get the message that I
have to close the first datareader in order to
execute, but then my code cannot proceed because rdToProcess("DE_Number")
can no longer be read.
How can I solve this?
Many thanks and greetings for your help,
Michel