Concurrency violation: the UpdateCommand affected 0 records.

Note: This KB is taken from MSDN for my own personal reference.

When you use a DataAdapter object to write changes back to a database by means of a stored procedure, you may receive the following error message:

An unhandled exception of type 'System.Data.DBConcurrencyException' occurred in system.data.dll

Additional information: Concurrency violation: the UpdateCommand affected 0 records.

If the data is not updated correctly, you should receive a DataConcurrencyException exception instead of the above-mentioned error message.

WHY?

This problem can occur if the stored procedure runs the SET NOCOUNT ON statement.
Back to the top

How to fix it?

To receive an exception when the data is not updated properly, you must explicitly add the SET NOCOUNT OFF statement to the stored procedure.

Up Next
    Ebook Download
    View all
    Learn
    View all