Hi Deepak,
The following structure is used to implement the transaction.
Begin Transaction
Try
{Statements]
Commit Transaction
Catch Exception
Rollback Transaction
End Try
The steps to complete a transaction including update of tables using a
stored procedure are listed below:
a.Open the connection.
b.Create a Transaction Object over the Connection Object by calling
its Begin Transaction method. The Begin Transaction method must be
called before performing any of the database operations that will take
part in the transaction.
c.Set Command Object's transaction property to the transaction object.
This will let ADO.Net to know which actions to do to undo when the
transaction is rolled back.
d.All the statements must be placed in the Try Clause of the exception
handler.
e.Set the Command Object's Command Text property to name of the stored
procedure.
f.Add parameters to the stored procedure. For each parameter, set its
name, type and value and add it to the Command Object's parameter
collection.
g.After all the parameters are set call the ExecuteNonQuery method of
the command object which will execute the stored procedure.
h.Commit the changes to the Tables by using Commit method.
I have explained this in detail in my book. However, thought of
posting it here.
Regards
Bharati
http://www.vkinfotek.com
Open source with a difference.