I ran into something odd, and I'm not precisely sure why it is behaving this way. In a for each loop I am adding rows to a table for a cross reference. Using the following code:
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
Without the objCommand.CommandText = String.Empty line the CommandText is appending the insertSQL but that doesn't make any sense to me because I would expect the objCommand's commandText to be empty since it is in a using block.