|
-
Mar 13th, 2013, 07:25 AM
#1
Thread Starter
Hyperactive Member
[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
-
Mar 13th, 2013, 07:38 AM
#2
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.
-
Mar 13th, 2013, 08:37 AM
#3
Thread Starter
Hyperactive Member
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.
Last edited by DavidGraham167; Mar 13th, 2013 at 08:46 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|