Results 1 to 3 of 3

Thread: [RESOLVED] Concurrency Violation

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    350

    Resolved [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

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    350

    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
  •  



Click Here to Expand Forum to Full Width