Need help in using MySqlTransaction RRS feed

  • Question

  • User672081070 posted

    Hi all i would like to use MySqlTransaction in my requirement. Actually i am having a doubt regarding that i.e as per my requirement i will have to delete different values from database.
    The process i am doing is as follows. Assume that i am having 2 EmpIDs where this EmpID will hold different values which may be multiple. I will store the corresponding values for that particular EmpID using Dictionary and then i will save them to a list corresponding to the EmpID.
    Assume that i am having list element as follows
    For EmpID 1 i will have 1,2. I will check for the maximum value from the datbase in this list if exists i would like to delete this EmpID from the database.
    For EmpID 2 i will have 1,2. But in my database i will have 3 as maximum values. So this one fails . I would like to rollback the previously deleted item .
    Is it possible to do with a transaction if so can any one help me in solving this
    Sample i code

           obj.delete("storeprocname");   // this will occur when my list has maximum value
         //Here i would like to rollback my previous one referring to the delete method in class file }
    Saturday, September 10, 2011 2:08 AM

All replies

  • User-364289655 posted

    I think the way you want to handle this is inside a transaction, but no rolling back would be required, here's some psudo code:


    MySqlTransaction scope = new MySqlTranscation();
            check database for max value 
            if (should we insert this value)
                 insert record;
    Saturday, September 10, 2011 2:12 AM
  • User672081070 posted

    I will enter to that code when max list was found for the employee.

    Saturday, September 10, 2011 2:13 AM
  • User672081070 posted

    Hmm i think no one understand my question clearly so in simple scenario i am saying

    i am having a form which will have 2 text boxes and button when i click on button i would like to insert the text entered in the text boxes to database as separate rows.

    Assume i will have a bool value to pass while inserting if i give true for the first item it will get inserted, i will give false to the second one which i would like to insert. As i am having false i don't want to insert this so i have to roll back the previous one too

    a sample code

    button click
    string str="Dora";
    string str1="Babu";
    bool flag=true;
    if(i==1 && flag==true)
    inser str;
    if(j==1 && flag==false)
    Saturday, September 10, 2011 7:15 AM