Data Adapter Events

DataAdapter class(OleDb,Sql and Oracle) exposes three events that can be used as record and respond to the changes being made to the database.
These events are as follows: This event is raised before a DML (Insert,Update,Delete) operation is to take place on a particular row. The RowUpdating event can be used for to gain additional control on the update operation like retaining old values before the changes are being made,cancel a particular update based on certain business logic or schedule it to be done later as a batch process.

  • RowUpdated : This event is raised after a DML operation on a particular row is complete. The RowUpdated event can be used to respond to errors and exceptions that occur, have a retry logic and so on.

  • FillError : This event is raised when an error occurs during a FILL operation. In case of a FillError , the row that caused it is not added to the DataTable. Hence this event can be used to resolve that error and add it to the DataTable or exclude it and continue the Fill operation.
     

  • The snippet of code below shows how these events can be used. No exception handling code has been written for better understanding of code.

    You can compile the code using the following command at the command prompt.

    csc /r:System.data.dll DAEvents.cs

    You can run the DAEvents.exe at the command prompt. Happy Coding !!!  

    Hide comments

    Comments

    • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

    Plain text

    • No HTML tags allowed.
    • Web page addresses and e-mail addresses turn into links automatically.
    • Lines and paragraphs break automatically.
    Publish