J'ai rencontré quelque chose d'étrange, et je ne suis pas sûr exactement pourquoi il se comporte de cette façon. Dans un pour chaque boucle j'ajoute des rangées à une table pour une référence croisée. En utilisant le code suivant:SQLCommand ne pas effacer le texte de commande dans une boucle
For Each cp In pCheckPoints
If cp <> String.Empty Then
Dim insertSQL As New StringBuilder
With insertSQL
.Append("INSERT INTO [CheckpointMessage] (")
.Append(" [MessageID] ")
.Append(", [CheckPoint] ")
.Append(") VALUES (")
.Append(" @MessageID ")
.Append(", @Checkpoint ")
.Append(") ")
End With
Using objCommand As New SqlCommand(insertSQL.ToString, MySQLConnection)
With objCommand.Parameters
.AddWithValue("@MessageID", pMessageID)
.AddWithValue("@Checkpoint", cp)
End With
objCommand.ExecuteNonQuery()
objCommand.CommandText = String.Empty
End Using
End If
Next
Sans la ligne objCommand.CommandText = String.Empty CommandText est le InsertSQL mais l'ajout qui ne fait pas de sens pour moi parce que je me attends commandText du ObjCommand être vide, car il est dans un bloc utilisant.
qu'entendez-vous par « est le InsertSQL annexant »? Pouvez-vous expliquer cela en termes d'apparence du contenu, pendant le débogage? – shahkalpesh