• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

Deletion in Transaction(OffTopic)

We have a transaction where are making a series of delete and Insert.
Here I am checking whether the record is deleted or not.
If the record is deleted I want to insert the data.
Since this is a in a transaction the physical delete is not happening.
Here my running a select query to read the data from the database (Oracle)
My logic always goes to update since physical delete is not made.

3 Solutions
If you are in a transaction, then if you try the delete, then do the insert. If the delete fails, it will presumably error and roll back the transaction, and therefore so will the insert. If you don't try the delete, then do the update. Or am I misunderstanding what you are asking?
A simple solution, if the transaction is via the Transaction property in Connection object and Command object, then set a boolean flag indicating the delete happened.
If u are doing a Delete operation then u will be using the ExecuteNonQuery method of the command object.
This method returns the number of rows affected buy the query. U can check that.

Or if there is a any problem with the delete then an exception will occur. U can rollback the transaction. If the particular delete does not cause an exception and if no rows are affected then it means that the particular where row(filtered by where clause) did not exist in the database.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now