[RESOLVED] Concurrency Violation
I have a SQL database with a simple table (InstTypes), the fields and contents are as shown below:
No Description
1 aa
2 bb
3 cc
I can edit the datagrid and on the save button I have the following code
Private Sub btnOK_Click(sender As System.Object, e As System.EventArgs) Handles btnOK.Click
Me.Validate()
Me.InstTypesBindingSource.EndEdit()
Me.InstTypesTableAdapter.Update(Me.MIS3_new1DataSet.InstTypes)
Me.Close()
End Sub
"No" is auto-incrementing and is read only.
If I change "bb" to "dd" and try to save I get the following error.
Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.
The update command is shown below.
UPDATE [dbo].[InstTypes] SET [No]=@No, [Description]=@Description WHERE (([No]=@No) AND ([Description]=@Description))
What am I doing wrong?
Thanks
Re: Concurrency Violation
The 'No' field should be set as a Primary Key.
This will allow you (and VB, etc) to know that you can easily identify each row uniquely. In terms of VB, it should automatically realise that the Where clause only needs the 'No' field.
Re: Concurrency Violation
Thanks.
I've added a the primary.
I also changed the update command.
UPDATE [dbo].[InstTypes] SET [No]=@No, [Description]=@Description WHERE ([No]=@No)
It is now working.