当前位置: 首页>>代码示例>>C#>>正文


C# SqlTransaction.Rollback方法代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlTransaction.Rollback方法的典型用法代码示例。如果您正苦于以下问题:C# SqlTransaction.Rollback方法的具体用法?C# SqlTransaction.Rollback怎么用?C# SqlTransaction.Rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlTransaction的用法示例。


在下文中一共展示了SqlTransaction.Rollback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeleteCopy

        public int DeleteCopy(LIB.CopyDTO copy, SqlTransaction trans)
        {
            bool isInScopeCreated = false;

            int rs;

            if (trans == null)
            {
                isInScopeCreated = true;
                trans = ConnectionManager.Con.BeginTransaction("CAT_CRE_TRANSACT");
            }

            CopyDAO dao = new CopyDAO();
            rs = dao.DeleteCopy(copy, trans);

            if (isInScopeCreated)
            {
                if (rs == 0)
                    trans.Rollback();
                else
                    trans.Commit();
            }

            return rs;
        }
开发者ID:lunardrik,项目名称:se0425-capstone-project-lib,代码行数:25,代码来源:CopyBUS.cs

示例2: addunit

        public void addunit()
        {
            tr = Conn.BeginTransaction();

                try
                {
                    sb = new StringBuilder();
                    sb.Append("INSERT INTO UNIT (UnitId,UnitName,UnitNameEng)");
                    sb.Append(" VALUES (@UnitId,@UnitName,@UnitNameEng)");
                    string sqlAdd;
                    sqlAdd = sb.ToString();

                    com.CommandText = sqlAdd;
                    com.CommandType = CommandType.Text;
                    com.Connection = Conn;
                    com.Transaction = tr;
                    com.Parameters.Clear();
                    com.Parameters.Add("@UnitId", SqlDbType.NVarChar).Value = txtUnitId.Text.Trim();
                    com.Parameters.Add("@UnitName", SqlDbType.NVarChar).Value = txtUnitName.Text.Trim();
                    com.Parameters.Add("@UnitNameEng", SqlDbType.NVarChar).Value = txtUnitNameEng.Text.Trim();
                    com.ExecuteNonQuery();
                    tr.Commit();

                }
                catch
                {
                    MessageBox.Show("คุณป้อนรหัสหน่วยนับสินค้าซ้ำ !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    tr.Rollback();
                }
        }
开发者ID:itktc,项目名称:projectktc-v2,代码行数:30,代码来源:frmUnit.cs

示例3: ExecuteNonQuery

 public void ExecuteNonQuery(SqlCommand sqlCmd)
 {
     using (SqlConnection sqlConn = new SqlConnection())
     {
         try
         {
             sqlConn.ConnectionString = strSqlConnectionString;
             if (sqlConn.State != ConnectionState.Open)
             {
                 sqlConn.Open();
             }
             sqlTrans = sqlConn.BeginTransaction("ExecuteNonQueryTransaction");
             sqlCmd.Connection = sqlConn;
             sqlCmd.Transaction = sqlTrans;
             sqlCmd.ExecuteNonQuery();
             sqlTrans.Commit();
         }
         catch (SqlException exSql)
         {
             SqlException ex = exSql;
             try
             {
                 if (sqlTrans != null)
                 {
                     sqlTrans.Rollback("ExecuteNonQueryTransaction");
                 }
             }
             catch (SqlException exRollback)
             {
                 ex = exRollback;
             }
             throw ex;
         }
     }
 }
开发者ID:dsbissett,项目名称:chonet,代码行数:35,代码来源:DataAccess.cs

示例4: Perform

        public void Perform(SqlTransaction transaction, SqlProjectInfo project, CommandAdder commandAdder)
        {
            var criticalError = false;
            try
            {

                using (var command = transaction.Connection.CreateCommand())
                {
                    command.CommandText = Entity.Content;
                    command.Transaction = transaction;
                    command.ExecuteNonQuery();
                }

                Logger.Log("created {0}", Entity);
            }
            catch (Exception ex)
            {
                criticalError = true;
                Logger.Log("failed while trying to create {0}", Entity);
                Logger.Log(ex);
                transaction.Rollback();
            }
            finally
            {
                if (!criticalError)
                {
                    // command to update memory data must be performed only after sql commands
                    commandAdder(new LambdaCommand((_, proj, _a) => UpdateProjectInfo(proj)));
                }
            }
        }
开发者ID:vlova,项目名称:TSqlWatcher,代码行数:31,代码来源:CreateCommand.cs

示例5: CreatePaySalary

        public int CreatePaySalary(PaySalary newPaySalary)
        {
            int result = -1;
            try
            {
                conn = db.openConn();
                tr = conn.BeginTransaction();
                sb = new StringBuilder();
                sb.Remove(0, sb.Length);
                sb.Append("INSERT INTO tbPaySalary(payID,psnCode,payStartDate,payEndDate,period,salary,revenceAll,netIncome,total,pSalary,pOt,pWork,ppSo,psLa,psLast,psLess,psReam,psIns,psPenalty)");
                sb.Append(" VALUES (@payID,@psnCode,@payStartDate,@payEndDate,@period,@salary,@revenceAll,@netIncome,@total,@pSalary,@pOt,@pWork,@ppSo,@psLa,@psLast,@psLess,@psReam,@psIns,@psPenalty)");

                string sqlsave;
                sqlsave = sb.ToString();

                comm = new SqlCommand();
                comm.Connection = conn;
                comm.Transaction = tr;
                comm.CommandText = sqlsave;
                comm.Parameters.Clear();
                comm.Parameters.Add("@payID", SqlDbType.NVarChar).Value = newPaySalary.payID;
                comm.Parameters.Add("@psnCode", SqlDbType.NVarChar).Value = newPaySalary.psnCode;
                comm.Parameters.Add("@payStartDate", SqlDbType.NVarChar).Value = newPaySalary.payStartDate;
                comm.Parameters.Add("@payEndDate", SqlDbType.NVarChar).Value = newPaySalary.payEndDate;
                comm.Parameters.Add("@period", SqlDbType.NVarChar).Value = newPaySalary.period;
                comm.Parameters.Add("@salary", SqlDbType.NVarChar).Value = newPaySalary.salary;
                comm.Parameters.Add("@revenceAll", SqlDbType.NVarChar).Value = newPaySalary.revenceAll;
                comm.Parameters.Add("@netIncome", SqlDbType.NVarChar).Value = newPaySalary.netIncome;
                comm.Parameters.Add("@total", SqlDbType.NVarChar).Value = newPaySalary.total;
                comm.Parameters.Add("@pSalary", SqlDbType.NVarChar).Value = newPaySalary.pSalary;
                comm.Parameters.Add("@pOt", SqlDbType.NVarChar).Value = newPaySalary.pOt;
                comm.Parameters.Add("@pWork", SqlDbType.NVarChar).Value = newPaySalary.pWork;
                comm.Parameters.Add("@ppSo", SqlDbType.NVarChar).Value = newPaySalary.ppSo;
                comm.Parameters.Add("@psLa", SqlDbType.NVarChar).Value = newPaySalary.psLa;
                comm.Parameters.Add("@psLast", SqlDbType.NVarChar).Value = newPaySalary.psLast;
                comm.Parameters.Add("@psLess", SqlDbType.NVarChar).Value = newPaySalary.psLess;
                comm.Parameters.Add("@psReam", SqlDbType.NVarChar).Value = newPaySalary.psReam;
                comm.Parameters.Add("@psIns", SqlDbType.NVarChar).Value = newPaySalary.psIns;
                comm.Parameters.Add("@psPenalty", SqlDbType.NVarChar).Value = newPaySalary.psPenalty;
                comm.ExecuteNonQuery();
                tr.Commit();

                result = 1;

            }
            catch (Exception ex)
            {
                tr.Rollback();
                conn.Close();
                return result;
                throw ex;

            }
            finally
            {
                conn.Close();
            }
            return result;
        }
开发者ID:marcpiulachs,项目名称:sttproject,代码行数:59,代码来源:PaySalaryService.cs

示例6: ExecuteDataset

        public static DataSet ExecuteDataset(SqlCommand command, SqlConnection connection, SqlTransaction transaction)
        {
            bool mustCloseConnection = false;

            #region Check
            if (connection == null) throw new ArgumentNullException("connection");

            if (command == null) throw new ArgumentNullException("command");

            if (connection.State != ConnectionState.Open)
            {
                mustCloseConnection = true;
                connection.Open();
            }
            else
            {
                mustCloseConnection = false;
            }

            if (transaction != null)
            {
                if (transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
                command.Transaction = transaction;
            }
            #endregion

            command.Connection = connection;

            command.Transaction = transaction;

            using (SqlDataAdapter da = new SqlDataAdapter(command))
            {
                DataSet retval = new DataSet();

                if (transaction == null)
                {
                    da.Fill(retval);
                }
                else
                {
                    try
                    {
                        da.Fill(retval);
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }
                }

                if (mustCloseConnection)
                    connection.Close();

                return retval;
            }
        }
开发者ID:chanfengsr,项目名称:AllPrivateProject,代码行数:58,代码来源:OutPutSQLHelper.cs

示例7: CreateLabel

    public int CreateLabel(Label newLabel)
    {
        int result = -1;
        try
        {
            conn = db.openConn();
            tr = conn.BeginTransaction();
            sb = new StringBuilder();
            sb.Remove(0, sb.Length);
            sb.Append("INSERT INTO Label(Id,PartName,SerialNo,PrintTime,Line,Ckt,Model,OilType,OilWeight,Status,Run,MM)");
            sb.Append(" VALUES (@Id,@PartName,@SerialNo,@PrintTime,@Line,@Ckt,@Model,@OilType,@OilWeight,@Status,@Run,@MM)");

            string sqlsave;
            sqlsave = sb.ToString();

            comm = new SqlCommand();
            comm.Connection = conn;
            comm.Transaction = tr;
            comm.CommandText = sqlsave;
            comm.Parameters.Clear();
            comm.Parameters.Add("@Id", SqlDbType.NVarChar).Value = newLabel.Id;
            comm.Parameters.Add("@PartName", SqlDbType.NVarChar).Value = newLabel.PartName;
            comm.Parameters.Add("@SerialNo", SqlDbType.NVarChar).Value = newLabel.SerialNo;
            comm.Parameters.Add("@PrintTime", SqlDbType.DateTime).Value =newLabel.PrintTime;
            comm.Parameters.Add("@Line", SqlDbType.NVarChar).Value = newLabel.Line;
            comm.Parameters.Add("@Ckt", SqlDbType.NVarChar).Value = newLabel.Ckt;
            comm.Parameters.Add("@Model", SqlDbType.NVarChar).Value = newLabel.Model;
            comm.Parameters.Add("@OilType", SqlDbType.NVarChar).Value = newLabel.OilType;
            comm.Parameters.Add("@OilWeight", SqlDbType.NVarChar).Value = newLabel.OilWeight;
            comm.Parameters.Add("@Status", SqlDbType.NVarChar).Value = newLabel.Status;
            comm.Parameters.Add("@Run", SqlDbType.NVarChar).Value = newLabel.Run;
            comm.Parameters.Add("@MM", SqlDbType.NVarChar).Value = newLabel.MM;

            comm.ExecuteNonQuery();
            tr.Commit();
            logger.Fatal(" Save Complate ");
            result = 1;

        }
        catch (Exception ex)
        {
            logger.Fatal(" Save Not complate "+ex.Message);
            tr.Rollback();
            conn.Close();
            return result;
            throw ex;

        }
        finally
        {

            conn.Close();
        }
        return result;
    }
开发者ID:marcpiulachs,项目名称:sttproject,代码行数:55,代码来源:Lservice.cs

示例8: DeleteCatalogue

        public int DeleteCatalogue(CatalogueDTO catalogue, SqlTransaction trans)
        {
            CatalogueDAO dao = new CatalogueDAO();
            CopyBUS copyBus = new CopyBUS();
            bool isInScopeCreated = false;

            int rs = 1;

            if (trans == null)
            {
                isInScopeCreated = true;
                trans = ConnectionManager.Con.BeginTransaction("CAT_DEL_TRANSACT");
            }

            List<CopyDTO> list = copyBus.GetCopyByISBN(catalogue.ISBN);
            foreach (CopyDTO copyDTO in list)
            {
                rs = rs & copyBus.DeleteCopy(copyDTO, trans);
                if (rs == 0)
                    break;
            }

            if (rs == 0)
            {
                if (isInScopeCreated)
                    trans.Rollback();
            }
            else
            {
                rs = rs & dao.DeleteCatalogue(catalogue, trans);

                if (isInScopeCreated)
                    if (rs == 0)
                        trans.Rollback();
                    else
                        trans.Commit();
            }

            return rs;
        }
开发者ID:lunardrik,项目名称:se0425-capstone-project-lib,代码行数:40,代码来源:CatalogueBUS.cs

示例9: CreateFinishingLabel

        public int CreateFinishingLabel(FinshingLabel newFinshingLabel)
        {
            int result = -1;
            try
            {
                conn = db.openConn();
                tr = conn.BeginTransaction();
                sb = new StringBuilder();
                sb.Remove(0, sb.Length);
                sb.Append("INSERT INTO finishing_labels(barcode,complete_no,rev,place_name,product_barcode_date,product_text_date,line,shift,serial,print_date,user_create_name,status)");
                sb.Append(" VALUES (@barcode,@complete_no,@rev,@place_name,@product_barcode_date,@product_text_date,@line,@shift,@serial,@print_date,@user_create_name,@status)");

                string sqlsave;
                sqlsave = sb.ToString();

                comm = new SqlCommand();
                comm.Connection = conn;
                comm.Transaction = tr;
                comm.CommandText = sqlsave;
                comm.Parameters.Clear();
                comm.Parameters.Add("@barcode", SqlDbType.NVarChar).Value = newFinshingLabel.Barcode;
                comm.Parameters.Add("@complete_no", SqlDbType.NVarChar).Value = newFinshingLabel.CompleteNo;
                comm.Parameters.Add("@rev", SqlDbType.NVarChar).Value = newFinshingLabel.Rev;
                comm.Parameters.Add("@place_name", SqlDbType.NVarChar).Value = newFinshingLabel.PlaceName;
                comm.Parameters.Add("@product_barcode_date", SqlDbType.NVarChar).Value = newFinshingLabel.ProductBarCodeDate;
                comm.Parameters.Add("@product_text_date", SqlDbType.NVarChar).Value = newFinshingLabel.ProductTextDate;
                comm.Parameters.Add("@line", SqlDbType.NVarChar).Value = newFinshingLabel.Line;
                comm.Parameters.Add("@shift", SqlDbType.NVarChar).Value = newFinshingLabel.Shift;
                comm.Parameters.Add("@serial", SqlDbType.NVarChar).Value = newFinshingLabel.Serial;
                comm.Parameters.Add("@print_date", SqlDbType.DateTime).Value = newFinshingLabel.PrintDate;
                comm.Parameters.Add("@user_create_name", SqlDbType.NVarChar).Value = newFinshingLabel.UserCreateName;
                comm.Parameters.Add("@status", SqlDbType.NVarChar).Value = newFinshingLabel.Status ;
                comm.ExecuteNonQuery();
                tr.Commit();

                result = 1;

            }
            catch (Exception ex)
            {
                tr.Rollback();
                conn.Close();
                return result;
                throw ex;

            }
            finally
            {
                conn.Close();
            }
            return result;
        }
开发者ID:marcpiulachs,项目名称:sttproject,代码行数:52,代码来源:FinishLabelService.cs

示例10: CreateMillin

        public int CreateMillin(Millin newMillin)
        {
            int result = -1;
            try
            {
                conn = db.openConn();
                tr = conn.BeginTransaction();
                sb = new StringBuilder();
                sb.Remove(0, sb.Length);
                sb.Append("INSERT INTO tbMillin(psnCode,cause,mFormat,note,mdateStart,mhurStart,mdateEnd,mhurEnd,mdateAll,mhurAll,mless,mtime)");
                sb.Append(" VALUES (@psnCode,@cause,@mFormat,@note,@mdateStart,@mhurStart,@mdateEnd,@mhurEnd,@mdateAll,@mhurAll,@mless,@mtime)");

                string sqlsave;
                sqlsave = sb.ToString();

                comm = new SqlCommand();
                comm.Connection = conn;
                comm.Transaction = tr;
                comm.CommandText = sqlsave;
                comm.Parameters.Clear();
                comm.Parameters.Add("@psnCode", SqlDbType.NVarChar).Value = newMillin.psnCode;
                comm.Parameters.Add("@cause", SqlDbType.NVarChar).Value = newMillin.cause;
                comm.Parameters.Add("@mFormat", SqlDbType.NVarChar).Value = newMillin.mFormat;
                comm.Parameters.Add("@note", SqlDbType.NVarChar).Value = newMillin.note;
                comm.Parameters.Add("@mdateStart", SqlDbType.NVarChar).Value = newMillin.mdateStart;
                comm.Parameters.Add("@mhurStart", SqlDbType.NVarChar).Value = newMillin.mhurStart;
                comm.Parameters.Add("@mdateEnd", SqlDbType.NVarChar).Value = newMillin.mdateEnd;
                comm.Parameters.Add("@mhurEnd", SqlDbType.NVarChar).Value = newMillin.mhurEnd;
                comm.Parameters.Add("@mdateAll", SqlDbType.NVarChar).Value = newMillin.mdateAll;
                comm.Parameters.Add("@mhurAll", SqlDbType.NVarChar).Value = newMillin.mhurAll;
                comm.Parameters.Add("@mless", SqlDbType.NVarChar).Value = newMillin.mless;
                comm.Parameters.Add("@mtime", SqlDbType.NVarChar).Value = newMillin.mtime;
                comm.ExecuteNonQuery();
                tr.Commit();

                result = 1;

            }
            catch (Exception ex)
            {
                tr.Rollback();
                conn.Close();
                return result;
                throw ex;

            }
            finally
            {
                conn.Close();
            }
            return result;
        }
开发者ID:marcpiulachs,项目名称:sttproject,代码行数:52,代码来源:MillinService.cs

示例11: CreatePringtingLabel

        public int CreatePringtingLabel(PrintingLabels newPrintingLabels)
        {
            int result = -1;
            try
            {
                conn = db.openConn();
                tr = conn.BeginTransaction();
                sb = new StringBuilder();
                sb.Remove(0, sb.Length);
                sb.Append("INSERT INTO printing_labels(barcode,part,product_date,serial,shift,rev,color_no,process,mold_no,user_create_name,create_date,status)");
                sb.Append(" VALUES (@barcode,@part,@product_date,@serial,@shift,@rev,@color_no,@process,@mold_no,@user_create_name,@create_date,@status)");

                string sqlsave;
                sqlsave = sb.ToString();

                comm = new SqlCommand();
                comm.Connection = conn;
                comm.Transaction = tr;
                comm.CommandText = sqlsave;
                comm.Parameters.Clear();
                comm.Parameters.Add("@barcode", SqlDbType.NVarChar).Value = newPrintingLabels.BarCode;
                comm.Parameters.Add("@part", SqlDbType.NVarChar).Value = newPrintingLabels.Part;
                comm.Parameters.Add("@product_date", SqlDbType.NVarChar).Value = newPrintingLabels.ProductDate;
                comm.Parameters.Add("@serial", SqlDbType.NVarChar).Value = newPrintingLabels.Serial;
                comm.Parameters.Add("@shift", SqlDbType.NVarChar).Value = newPrintingLabels.Shift;
                comm.Parameters.Add("@rev", SqlDbType.NVarChar).Value = newPrintingLabels.Rev;
                comm.Parameters.Add("@color_no", SqlDbType.NVarChar).Value = newPrintingLabels.ColorNo;
                comm.Parameters.Add("@process", SqlDbType.NVarChar).Value = newPrintingLabels.Process;
                comm.Parameters.Add("@mold_no", SqlDbType.NVarChar).Value = newPrintingLabels.Mold;
                comm.Parameters.Add("@user_create_name", SqlDbType.NVarChar).Value = newPrintingLabels.UserCreateName;
                comm.Parameters.Add("@create_date", SqlDbType.DateTime).Value = newPrintingLabels.CreateDate;
                comm.Parameters.Add("@status", SqlDbType.NVarChar).Value = newPrintingLabels.Status;
                comm.ExecuteNonQuery();
                tr.Commit();

                result = 1;

            }
            catch (Exception ex)
            {
                tr.Rollback();
                conn.Close();
                return result;
                throw ex;

            }
            finally
            {
                conn.Close();
            }
            return result;
        }
开发者ID:marcpiulachs,项目名称:sttproject,代码行数:52,代码来源:PrintingService.cs

示例12: deletesupplier

        public void deletesupplier()
        {
            if (MessageBox.Show("คุณต้องการลบผู้ขาย ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {

                tr = Conn.BeginTransaction();

                try
                {
                    sb = new StringBuilder();
                    sb.Append("DELETE SUPPLIER");
                    sb.Append(" WHERE ([email protected])");
                    string sqlDelete;
                    sqlDelete = sb.ToString();

                    com.CommandText = sqlDelete;
                    com.CommandType = CommandType.Text;
                    com.Connection = Conn;
                    com.Transaction = tr;
                    com.Parameters.Clear();
                    com.Parameters.Add("@SupplierId", SqlDbType.NVarChar).Value = txtSupplierID.Text.Trim();
                    int result;
                    result = com.ExecuteNonQuery();
                    if (result == 0)
                    {
                        tr.Rollback();
                        MessageBox.Show("ข้อมูลที่ต้องการลบไม่ถูกต้อง !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtSupplierID.SelectAll();
                    }
                    else
                    {
                        tr.Commit();

                        //MessageBox.Show("ลบชื่อหน่วยนับสินค้า เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);

                       // ClearAllData();//Clear ข้อมูลจาก textbox
                        ShowData();
                        FormatDgvSupplierList();

                        btnAdd.Enabled = true;
                        btnEdit.Enabled = false;
                        btnDelete.Enabled = false;
                    }
                }
                catch (Exception ex)
                {
                    tr.Rollback();
                    MessageBox.Show("เกิดข้อผิดพลาด เนื่องจาก " + ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
开发者ID:itktc,项目名称:projectktc-v2,代码行数:51,代码来源:frmSupplier.cs

示例13: ExecuteNonQuery

        public bool ExecuteNonQuery(string query)
        {
            if (Conectar())
            {
                command = new SqlCommand();
                command.Connection = sqlConn;
                command.CommandType = CommandType.Text;
                command.CommandText = query;

                transaction = sqlConn.BeginTransaction();
                command.Transaction = transaction;
                try
                {
                    SqlCommandBuilder.DeriveParameters(command);

                    command.ExecuteNonQuery();

                    transaction.Commit();

                    Desconectar();

                    return true;
                }
                catch (SqlException sqlEx)
                {
                    transaction.Rollback();
                    mensajeSQLExcepcion = sqlEx.Message;
                    return false;
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    mensajeExcepcion = ex.Message;
                    return false;
                }
            }
            return false;
        }
开发者ID:JonathanFernandez,项目名称:Pirelli,代码行数:38,代码来源:AdoConn.cs

示例14: deletecompany

        public void deletecompany()
        {
            //if (MessageBox.Show("คุณต้องการลบชื่อบริษัท  ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            //{

                tr = Conn.BeginTransaction();

                try
                {
                    sb = new StringBuilder();
                    sb.Append("DELETE Company");
                    sb.Append(" WHERE ([email protected])");
                    string sqlDelete;
                    sqlDelete = sb.ToString();

                    com.CommandText = sqlDelete;
                    com.CommandType = CommandType.Text;
                    com.Connection = Conn;
                    com.Transaction = tr;
                    com.Parameters.Clear();
                    com.Parameters.Add("@CompanyID", SqlDbType.NVarChar).Value = txtCompanyId.Text.Trim();
                    int result;
                    result = com.ExecuteNonQuery();
                    if (result == 0)
                    {
                        tr.Rollback();
                        MessageBox.Show("ข้อมูลที่ต้องการลบไม่ถูกต้อง !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtCompanyId.SelectAll();
                    }
                    else
                    {
                        tr.Commit();
                        //MessageBox.Show("ลบชื่อลูกค้า เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        ShowData();
                        FormatCompanyList();

                        btnAdd.Enabled = true;
                        btnEdit.Enabled = false;
                        btnDelete.Enabled = false;

                    }
                }
                catch (Exception ex)
                {
                    tr.Rollback();
                    MessageBox.Show("เกิดข้อผิดพลาด เนื่องจาก " + ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            //}
        }
开发者ID:itktc,项目名称:projectktc-v2,代码行数:50,代码来源:frmCompany.cs

示例15: ActualizarNaviera

        public static ResultadoTransaccion ActualizarNaviera(Int64 id, string nombre, string relacionPuertos)
        {
            resTransaccion = new ResultadoTransaccion();
            try
            {
                //Abrir Conexion
                conn = BaseDatos.Conexion();

                //Crear Transaccion
                transaction = conn.BeginTransaction();

                //Actualizar
                //objParams = SqlHelperParameterCache.GetSpParameterSet(BaseDatos.Conexion(), "SP_A_CLIENTES_DIRECCION");
                objParams = SqlHelperParameterCache.GetSpParameterSet(conn, "SP_U_PAPERLESS_NAVIERA");
                objParams[0].Value = id;
                objParams[1].Value = nombre;

                SqlCommand command = new SqlCommand("SP_U_PAPERLESS_NAVIERA", conn, transaction);
                command.Parameters.AddRange(objParams);
                command.CommandType = CommandType.StoredProcedure;
                command.ExecuteNonQuery();

                transaction.Commit();

                resTransaccion.Estado = Enums.EstadoTransaccion.Aceptada;
                resTransaccion.Accion = Enums.AccionTransaccion.Actualizar;
                resTransaccion.ObjetoTransaccion = id;
                //Registrar Actividad
                //LogActividadUsuarios log = new LogActividadUsuarios(cuenta.GetType().ToString(), cuenta.Id, Enums.TipoActividadUsuario.Edito, Base.Usuario.UsuarioConectado.Usuario);
                //LogActividades.clsLogActividadUsuariosADO.GuardaActividad(log);
                CreaRelacionPuertos(id, relacionPuertos, conn);
                resTransaccion.Descripcion = "Se actualizó naviera '" + nombre + "'.";
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                Log.EscribirLog(ex.Message);

                resTransaccion.Estado = Enums.EstadoTransaccion.Rechazada;
                resTransaccion.Descripcion = ex.Message;
            }
            finally
            {
                conn.Close();

            }

            return resTransaccion;
        }
开发者ID:TarekMulla,项目名称:cra,代码行数:49,代码来源:ClsNavierasDAO.cs


注:本文中的System.Data.SqlClient.SqlTransaction.Rollback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。