Concurrency violation on first new record

FreeriderUK

Well-known member
Joined
Jun 27, 2006
Messages
100
Location
London
Programming Experience
10+
Hi all,

when trying to execute the following code:
VB.NET:
Expense_PayeeTextBox.Text = cbEditPayees.SelectedItem.ToString
Me.Validate()
Me.ExpensesBindingSource.EndEdit()
Me.ExpensesTableAdapter.Update(MyCustomersDataSet.Expenses)
I get the following error:
Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

On the form, I have a datagridview (used for display only), two ComboBoxes - one for Payees and another for Categories.
After clicking the ADD button on the BindingNavigator, I then select an item from the Payees ComboBoxes and the above code is executed (I want to send text to a textbox which automatically gets entered into datagrid).

So far so good.

But when I do the same for the Categories ComboBox, I get the above error message.

The thing I don't understand is that this only happens after creating the very first record - If I manually add one record into this table (Access database) everything works fine.

Has anyone else had this problem?
Any possible solutions?

(I'm using VS2005)

Thanks.
 
Last edited by a moderator:
I forgot to say, I did find a way around it by using this code:

If ExpensesDataGridView.RowCount = 1 Then
Me.ExpensesTableAdapter.ClearBeforeFill = True
Me.ExpensesTableAdapter.Fill(MyCustomersDataSet.Expenses)
End If
---
It doesn't completely solve the problem though, so I'm still interested in more comments.
 
Back
Top