Results 1 to 6 of 6

Thread: "Concurrency violation: the DeleteCommand affected 0 of the expected 1 records."

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2019
    Posts
    136

    "Concurrency violation: the DeleteCommand affected 0 of the expected 1 records."

    I have an array of DataTables and Adapters

    In this instance I have assigned one of the tables to a unique DataTable varable "rs" which is associated with the giLastTableIndex index as appears in the update command below

    I wish to delete a row and update the DataTable

    Code:
    Dim rRow As DataRow
    
    For Each rRow In rs.Rows
    				With rRow
    					If .Item("DVN_SHAFT") = sDVN_SHAFT And .Item("DP") = fDP And .Item("PR_ANG") = fPR_ANG And .Item("DVR_N_T") = fDVR_N_T And .Item("DVN_N_T") = fDVN_N_T And .Item("DVR_AD") = fDVR_AD And .Item("DVN_AD") = fDVN_AD Then
    						rRow.Delete()
    						Exit For
    
    					End If
    				End With
    Next rRow
    
    iRet = gda(giLastTableIndex).Update(gdt(giLastTableIndex))
    The update results in the concurrency violation

    I have looked for instances where I am holding the DataTable open with another variable and I do not believe I have any.

    Suggestions?

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,522

    Re: "Concurrency violation: the DeleteCommand affected 0 of the expected 1 records."

    My only suggestion would be to find where/what has changed the row in the database table prior to this update call.

    A System.Data.DBConcurrencyException in Visual Basic occurs during a DataAdapter.Update operation when the database detects that the row you are trying to modify or delete has changed since you originally loaded it into memory. Because ADO.NET uses optimistic concurrency by default, its generated SQL commands (UpdateCommand or DeleteCommand) look for an exact match of all original column values in the WHERE clause. If another user or process altered even one value, the query affects 0 rows, triggering the exception

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,426

    Re: "Concurrency violation: the DeleteCommand affected 0 of the expected 1 records."

    Why an array of DataTables?’ You’re aware of the DataSet? A DataSet is a collection of DataTables…

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2019
    Posts
    136

    Re: "Concurrency violation: the DeleteCommand affected 0 of the expected 1 records."

    Good Point. I suspect I did not know that at the time that I was creating the code. Do you think that would change the outcome?

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,426

    Re: "Concurrency violation: the DeleteCommand affected 0 of the expected 1 records."

    Quote Originally Posted by Richard Friedman View Post
    Good Point. I suspect I did not know that at the time that I was creating the code. Do you think that would change the outcome?
    Try googling... 'vb.net update all datatables from dataset'

    There's a lot of information available...

  6. #6
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,522

    Re: "Concurrency violation: the DeleteCommand affected 0 of the expected 1 records."

    Quote Originally Posted by Richard Friedman View Post
    Good Point. I suspect I did not know that at the time that I was creating the code. Do you think that would change the outcome?
    If this is the same project as you were working on in previous posts then changing to dataset would involve a major rewrite. Don't know if would solve your problem because we don't know what's causing the problem. Other than something seems to have altered the record in the database table that your trying to update after the datatable was filled.

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