Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.

Posted On // Leave a Comment
"Concurrency violation: the UpdateCommand affected 0 of the expected 1 records."

I got that message when i was try to update database when my DevExpress GridControl changed. Heres the wrong code:

Private Sub AdvBandedGridView1_RowUpdated(ByVal sender As System.Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowObjectEventArgs) Handles AdvBandedGridView1.RowUpdated
        If AdvBandedGridView1.UpdateCurrentRow Then
            Try
                DAUniFix.Update(DsUniFix)
            Catch ex As Exception
                XtraMessageBox.Show(_LookAndFeel, ex.Message, Me.Text)
            End Try
        End If
    End Sub

To fix this error, make sure your table has primary key and simply add two line of syntax as shown below


Private Sub AdvBandedGridView1_RowUpdated(ByVal sender As System.Object, ByVal e As DevExpress.XtraGrid.Views.Base.RowObjectEventArgs) Handles AdvBandedGridView1.RowUpdated
        If AdvBandedGridView1.UpdateCurrentRow Then
            Try
                Me.Validate()
                Me.UniFixBindingSource.EndEdit()
                DAUniFix.Update(DsUniFix)
            Catch ex As Exception
                XtraMessageBox.Show(_LookAndFeel, ex.Message, Me.Text)
            End Try
        End If
    End Sub

0 komentar: