当 SubmitChanges 失败时,我在撤消失败的 InsertOnSubmit 时遇到问题。这是代码:
Dim NewFac As New t_Facility With
{.FK_Instance_ID = guInstance_ID,
.FK_AccountType_ID = guAccountType_ID,
.FK_ATP_ID = guATP_ID,
.FK_Repayment_ID = guRepaymentType_ID,
.FK_InterestType_ID = guInterestType_ID,
.FK_FT_ID = guFacilitiesType_ID,
.NewRecord = bNewRecord,
.IndexNum = iIndexNum,
.SortCode = sSortCode,
.AccountNumber = sAccountNumber,
.Balance = decBalance,
.LastSanction = decLastSanctioned,
.Proposed = decProposed,
.Term_MTHs = iTerm_MTHS,
.Term_Expiry = dTerm_Expiry,
.InterestRate = decInterestRate,
.ArrangementFee = decArrangementFee,
.DateTime_From = Now(),
.ID = guFacilities_ID}
db.t_Facilities.InsertOnSubmit(NewFac)
Try
db.SubmitChanges()
Catch e As Exception
Console.WriteLine(e)
MessageBox.Show(e.Message & ". Please correct the field and try again", "ERROR", MessageBoxButton.OK, MessageBoxImage.Stop)
Exit Sub 'Takes the user back to the form to correct the value
End Try
当他们再次点击提交时,它会返回并在同一点以与原始提交相同的值失败,而忽略用户输入的新值。
“NewFac”中的值是更正后的新值。我已经在调试中手动检查了这一行:“db.t_Facilities.InsertOnSubmit(NewFac)”
我假设我需要以某种方式从捕获中的“db.t_Facilities.InsertOnSubmit(NewFac)”中删除包含不正确值的失败“NewFac”,但我看不到这样做的方法吗?
仅供参考:我从这里得到了这种方法的主要内容:https ://msdn.microsoft.com/en-us/library/bb763516
任何帮助,将不胜感激。