I have the following code, that in my head should create a new row in a table:
Dim fin As Boolean
Dim db2 As New ChecklistModeldbmlDataContext
For Each a In bServers
If collection("fin" & a.ServerName) = "true, false" Or collection("fin" & a.ServerName) = "true,false" Then
fin = True
Else
fin = False
End If
bLog.AMLogID = amLog.LogID
bLog.ByteCount = collection("bytes" & a.ServerName)
bLog.DurationHours = collection("hours" & a.ServerName)
bLog.DurationMinutes = collection("minutes" & a.ServerName)
bLog.DurationSeconds = collection("seconds" & a.ServerName)
bLog.IsFinished = fin
bLog.ServerID = a.ServerID
bLog.DetailsAndErrors = collection("details" & a.ServerName)
db2.BackupLogs.InsertOnSubmit(bLog)
db2.SubmitChanges()
Next
It only ever adds one record in to the table and then errors with Cannot add an entity that already exists.
Now it should enter 4 rows into the table, but I can't work out why the above gives me that error.
I've also tried having the db2.SubmitChanges() outside of the for each and it just inserts the last row.
Any thoughts?