How to implement a Transaction

Declare a Paulovich Command object

            Command command = new Command();

            try {

                //define a CommandType on Enumerator
                command.CommandType = CommandType.StoredProcedure;

                //add values to object
                command.AddWithValue("param1", param1);
                command.AddWithValue("param2", param2);
                command.AddWithValue("param3", param3);

                //start a transaction
                command.BeginTransaction();
                
                command.ExecuteNonQuery("spExecuteProcedure");
                
                //if no error was fire execute Commit();
                command.Commit();

            } catch (Exception) {

                //otherwise RollBack() your Command
                command.RollBack();
                throw;
            }

Last edited Feb 25, 2008 at 6:46 PM by paulovich, version 2

Comments

No comments yet.