locked
how to put Transaction function if I use sqlHelper RRS feed

  • Question

  • User-635215137 posted

     Hi:

    I am using sqlHelper to communicate with database, very handy.

    I want to use Transaction to make sure all the data will be removed for a particula user. So I will use:

    1. Membership.DeleteUser(sUserName)

    2. Delete other related data in other tables .

    I want to make sure both 1 and 2 will be executed successfully, otherwise don't delete any data.

    Since I am using sqlHelper, I don't know where and how to use the transaction functions.

    I have googled for the help, most of them are using(such as below):  Command.transaction..., but I am using sqlHelper, so I don't know how to archive it

    SqlTransaction myTransaction = null;
    myTransaction =myConnection.BeginTransaction();
    myCommand.Transaction = myTransaction;
    catch (Exception ex)
      {
        string exception = ex.Message;
        myTransaction.Rollback();
      }
     Thanks
    JT 

     

     

    Thursday, March 19, 2009 6:34 PM

All replies

  • User-1557807525 posted

    Keep the transaction a global variable in class

    In that have Have a method

    Method 1 to have try catch finall block

    create a the instance of the transaction in method 1

    in catch do the roll back and in finally do the commit

    Method 2 to delete the user

    Method 3 to delete user related

    In Method 1 on try block call

    Method 3 // To avoid foreign key issues

    Method 2

    Friday, March 20, 2009 3:57 AM