Does ADO.NET Have Optimistic Concurrency for DataReader RRS feed

  • Question

  • Does ADO.NET have optimistic concurrency for the DataReader or is it only applied for DataAdapters?

    Here is my situation.  I get a dataset from a stored procedure using a DataReader, not a DataAdapter.  Then the user makes changes to the DataGridView and I use the event procedure to update the database.  I want to be sure ADO.NET has data integrity in mind even when I'm only using a DataReader.

    Thanks in advance!

    Ryan H

    Monday, June 20, 2011 1:33 PM


  • Hi Ryan,


    I've done some research, I find The RowUpdated event of the DataAdapter object can be used in conjunction with the techniques described earlier, to provide notification to your application of optimistic concurrency violations. RowUpdated occurs after each attempt to update a Modified row from a DataSet. This enables you to add special handling code, including processing when an exception occurs, adding custom error information, adding retry logic, and so on.(


    When an update is attempted, the original version of a changed row is compared against the existing row in the database. If the two are different, the update fails with a concurrency error. It is up to you at that point to reconcile the two rows, using business logic that you create.


    By the way, DataReader is used to retrieve a read-only, forward-only stream of data from a database.(

    My suggestion is to use dataadapter to update your database.

    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Ryan0827 Wednesday, June 22, 2011 11:00 AM
    Tuesday, June 21, 2011 7:35 AM