0 Replies - 234 Views - Last Post: 26 May 2014 - 11:48 PM Rate Topic: -----

#1 Kyi Kyi Naing  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-May 14

transaction error

Posted 26 May 2014 - 11:48 PM

  string personNo = "";
            SqlConnection con = new SqlConnection(cnStr);
            SqlCommand cmd = new SqlCommand();

            cmd.Connection = con;
            con.Open();

            try
            {
                tran = cn.BeginTransaction(IsolationLevel.ReadCommitted);

                cmd.CommandText = "Delete from tblFamilyRegistration where FamilyRegistrationCode ='" + familyCode + "'";
                cmd.CommandType = CommandType.Text;
                cmd.Transaction = tran;
                cmd.ExecuteNonQuery();

                cmd.CommandText = " Delete From tblFamilyRegistrationDetail where FamilyRegistrationCode ='" + familyCode + "'";
                cmd.CommandType = CommandType.Text;
                cmd.Transaction = tran;
                cmd.ExecuteNonQuery();

                for (int i = 0; i < arrpersonNo.Length; i++)
                {
                    if (i != arrpersonNo.Length - 1)
                        personNo += "PersonNo = '" + arrpersonNo[i] + "' or ";
                    else
                        personNo += "PersonNo = '" + arrpersonNo[i];
                }

                cmd.CommandText = string.Format("Delete from tblDeliveryDetail where {0}", personNo);
                cmd.CommandType = CommandType.Text;
                cmd.Transaction = tran;
                cmd.ExecuteNonQuery();

                tran.Commit();
                con.Close();

                return true;
            }
            catch (Exception ex)
            {
                ex.ToString();
                tran.Rollback();
                return false;
            }
          



i get the following error..
"The transaction is either not associated with the current connection or has been completed.".
why get I get the error?..

Is This A Good Question/Topic? 0
  • +

Page 1 of 1