I have 2 tables enquiry and details.
On save button click I have written
fbsave();
fbsavedetails();
fbsave() save the data in enquiry table and fbsavedetails() saves data in details table.
now if error occur in fbsavedetails() then both steps should be rollback.
is it possible?
You can explicitly create a transaction and pass that around, i.e.
Note that here you must also set the
Transactionon each command, hence why you need to pass it in, and all the commands must be on the same connection object.Or: you can use
TransactionScope; it is important that theOpen()happens inside theTransactionScopeto get automatic enlistment:or:
with the
TransactionScopeapproach, you don’t need to set anything special – most of it is automatic. You can of course optionally pass the connection into the methods, but they could also obtain their own connection, and in most cases it would work fine.