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
if(findMax(lst,iEmpID)
{
obj.delete("storeprocname");
}
else
{
}
public bool deletePayRoll(string storeproc,bool result)
{
if(result==true)
{
m_bFlag = false;
this.m_oConn = Utilities.GetConnection();
m_oCmd = new MySqlCommand(storeproc, m_oConn);
m_oCmd.CommandType = CommandType.StoredProcedure;
m_oCmd.Parameters.AddWithValue("_EmpId", EmpID);
m_oCmd.Parameters.AddWithValue("_FedTaxID", FedTaxID);
m_oCmd.Parameters.AddWithValue("_payperiodnumber", Payperiodnumber);
m_oCmd.Parameters.AddWithValue("_payyear", PayYear);
m_oCmd.Parameters.AddWithValue("_paymentdate", PaymentDate);
try
{
if (m_oConn.State != ConnectionState.Open)
{
m_oConn.Open();
}
if (m_oCmd.ExecuteNonQuery() > 0)
{
m_bFlag = true;
}
}
catch (MySqlException oSqlEx)
{
m_sbErrMsg.Length = 0;
m_sbErrMsg = Utilities.SqlErrorMessage(oSqlEx);
m_oErrlog.Add(m_sbErrMsg.ToString(), DateTime.Now);
}
catch (Exception oEx)
{
m_sbErrMsg = Utilities.ErrorMessage(oEx);
m_oErrlog.Add(m_sbErrMsg.ToString(), DateTime.Now);
}
finally
{
m_oConn.Close();
}
}else
{
}
return m_bFlag;
}
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;
i=1,j=1;
if(i==1 && flag==true)
inser str;
flag=false;
if(j==1 && flag==false)
rollback
}