【发布时间】:2012-06-04 04:05:41
【问题描述】:
我有以下代码,在我的脑海中应该在表格中创建一个新行:
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
它只会在表中添加一条记录,然后出现无法添加已存在的实体的错误。
现在它应该在表中输入 4 行,但我不知道为什么上面给了我这个错误。
我也尝试将 db2.SubmitChanges() 放在 for each 之外,它只是插入最后一行。
有什么想法吗?
【问题讨论】:
标签: asp.net-mvc vb.net linq-to-sql foreach