示例#1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.dgvGrid.Rows.Count == 0)
            {
                return;
            }
            if (MessageBox.Show("선택된 데이터를 삭제하시겠습니까?", "Delete", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            #region Transaction Decl
            SqlCommand     Cmd = new SqlCommand();
            SqlTransaction Txn;
            #endregion

            #region Connection Open
            Conn = new SqlConnection(ConnInfo);
            Conn.Open();
            #endregion

            #region Transaction Init
            Txn             = Conn.BeginTransaction("Begin Transaction");
            Cmd.Transaction = Txn;
            Cmd.Connection  = Conn;
            #endregion

            try
            {
                string delCustCode = dgvGrid.CurrentRow.Cells["CUSTCODE"].Value.ToString();

                #region Transaction Commit
                Cmd.CommandText = $"DELETE TB_CUST_NHJ WHERE CUSTCODE = '{delCustCode}'";
                Cmd.ExecuteNonQuery();
                Txn.Commit();
                #endregion

                MessageBox.Show("성공적으로 데이터를 삭제하였습니다.");
                btnSearch_Click(null, null);
            }
            catch (Exception ex)
            {
                // 오류가 났을 때는 ROLLBACK
                Txn.Rollback();
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                Conn.Close();
            }
        }
示例#2
0
 public void Rollback()
 {
     mTxn.Rollback();
     Dispose();
 }