I'm having a problem with undoing a failed InsertOnSubmit when SubmitChanges fails. Here's the code:
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
When they hit submit again, it comes back around and fails at the same point with the same values as the original submission ignoring the new values that the user input.
The values in "NewFac" are the corrected new values. I've checked them on this line manually in debug: "db.t_Facilities.InsertOnSubmit(NewFac)"
I assume i need to somehow remove the failed "NewFac" that contains the incorrect values from "db.t_Facilities.InsertOnSubmit(NewFac)" in the catch somehow, but i don't see a way to do this?
FYI: I got the principal of this approach from here: https://msdn.microsoft.com/en-us/library/bb763516
Any help would be appreciated.