none
Data update in RowDeleting event RRS feed

  • Question

  • Hi,

    I am modifying a couple of fields (say, A & B) of the row being deleted in the RowDeleting event of a data table. I have a delete trigger on this table which checks the values of the fields A & B and performs some action. What I have noticed is that this deleted record does not reflect the updated values for the fields A & B. What could be the reason? Am I missing something here?

    Please feel free to suggest the appropriate forum if this is not the one.

    Regards,
    dsanjag 

     

     

    Thursday, April 21, 2011 4:01 PM

Answers

  • no,

    once you mark a row as deleted, even if it has changed, it will be deleted, there will NOT be an update first, and then a delete.

    You'll have to change you logging; if every user accesses the db with his own credentials, you could use SESSION_USER to get his/her name, and the modified date is the current date (GetDate() function).

    regards,

    Nico

    Friday, April 22, 2011 1:57 PM

All replies

  • Hi dsanjag,

    what do you mean by trigger? a database trigger? If you delete a datarow, then it is marked as deleted (rowstate), and a subsequent update will delete the record in the database, based on its key or original values. There is no update before it's deleted, so the trigger would only see the old values.

    regards,

    Nico

    Thursday, April 21, 2011 4:18 PM
  • Hi Nico,

    Thanks for your reply!

    I have a SQL database delete trigger which captures the rowID, LastModifiedBy, and DateLastModified fields of the deleted record in a separate table. I am doing this to keep track of the deleted records and I need the ID of the person who deleted the record which is captured from the LastModifiedBy field.

    I am updating the LastModifiedBy and DateLastModified fields before the row is actually deleted in the RowDeleting event. I have traced the code and found that these fields are actually updated in the data table of the dataset, but these updates are not exposed to the delete trigger. I do understand that the rowstate is marked as deleted, but since I am updating a couple of fields before the row is actually deleted shouldn't this row contain the new values?

    Is there any other way to capture the updated fields in the delete trigger.

    Regards,
    dsanjag

    Friday, April 22, 2011 1:46 PM
  • no,

    once you mark a row as deleted, even if it has changed, it will be deleted, there will NOT be an update first, and then a delete.

    You'll have to change you logging; if every user accesses the db with his own credentials, you could use SESSION_USER to get his/her name, and the modified date is the current date (GetDate() function).

    regards,

    Nico

    Friday, April 22, 2011 1:57 PM