I'm using VB 2005 and an Access database in an application.
A form that I'm using has some bound controls on it.
The user enters some data into the controls, then clicks save to save the new record. If the user then keys more data into the controls and clicks save again, the update fails.
I use this code to determine the rowstate of the bindingsource.
Ctype(bsConfiguration.Current,DataRowView).Row.RowState
After the insert, the code returns Added {4}.
The new record is inserted into the database.
So when the update code is run, the rowstate is still Added {4}.
The update fails and returns a duplicate index, primary key, relationship ole db error. I believe the update statement is trying to insert the same record again.
Why doesn't the rowstate change after the insert?
What else do I do after inserting the record to get the next update to work?
A form that I'm using has some bound controls on it.
The user enters some data into the controls, then clicks save to save the new record. If the user then keys more data into the controls and clicks save again, the update fails.
I use this code to determine the rowstate of the bindingsource.
Ctype(bsConfiguration.Current,DataRowView).Row.RowState
After the insert, the code returns Added {4}.
The new record is inserted into the database.
So when the update code is run, the rowstate is still Added {4}.
The update fails and returns a duplicate index, primary key, relationship ole db error. I believe the update statement is trying to insert the same record again.
Why doesn't the rowstate change after the insert?
What else do I do after inserting the record to get the next update to work?
VB.NET:
Private Sub SaveConfiguration()
If formLoading OrElse bCancelMode Then Exit Sub
If Not Dirty Then Exit Sub
Try
If FormIsClosing Then Exit Sub
'fix 10/28/2008
If Me.Validate = False Then
Exit Sub
End If
If String.IsNullOrEmpty(txtConfigId.Text) Then
bsConfiguration.Current("ConfigurationId") = CreateNewConfigId()
FillConfigurationObject()
bsConfiguration.EndEdit()
With Configuration
taConfiguration.Insert(.ConfigId, .ConfigName, cboCustomer.EditValue, .SalesRepId, cboManufacturer.EditValue,
dtConfigDate.Text, .SalesRepMarkup, .TradeIn, .Payoff, .PONumber, .OrderedBy, .OrderedByEmail, .PrintLease, .LeaseOption, .PrintRetailprice, .TotalSaleAmount, .CommissionRate, .ManagementNotes,
.ServiceBaseCharge, .ServiceIncluded, .ServiceType, .UsageCharge, .ServiceOptions, .InstallContact, .InstallContactEmail, .PaymentMethod, .UseShipto, .MiscNotes, fMain.CurrentLogin, .Promotion)
End With
Else
bsConfiguration.EndEdit()
taConfiguration.Update(DsConfiguration.Configuration)
End If
Catch ex As OleDb.OleDbException
ErrorLog.WriteToErrorLog(ex.ToString, ex.StackTrace, SCP_UI.fConfiguration.SaveConfiguration")
Catch ex As System.Exception
ErrorLog.WriteToErrorLog(ex.ToString, ex.StackTrace, "SCP_UI.fConfiguration.SaveConfiguration")
MessageBox.Show(ex.ToString & vbCrLf & _
ex.Source & vbCrLf & _
ex.TargetSite.ToString & vbCrLf)
End Try
End Sub
Last edited by a moderator: