System.Data.Common.DbTransaction.Commit C# (CSharp) Method

Commit() public abstract method

public abstract Commit ( ) : void
return void
        public abstract void Commit();

Usage Example

示例#1
0
        public bool DeleteProduct(int exchangeId, int productId)
        {
            bool result = false;

            using (System.Data.Common.DbConnection dbConnection = this.database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction    = dbConnection.BeginTransaction();
                System.Data.Common.DbCommand     sqlStringCommand = this.database.GetSqlStringCommand("delete from Hishop_PointExChange_Products where [exChangeId]= @exChangeId and [ProductId] = @ProductId ");
                this.database.AddInParameter(sqlStringCommand, "exChangeId", System.Data.DbType.Int32, exchangeId);
                this.database.AddInParameter(sqlStringCommand, "ProductId", System.Data.DbType.Int32, productId);
                System.Data.Common.DbCommand sqlStringCommand2 = this.database.GetSqlStringCommand("update Hishop_PointExChange_PointExChanges set ProductNumber=ProductNumber-1 where Id=@Id");
                this.database.AddInParameter(sqlStringCommand2, "Id", System.Data.DbType.Int32, exchangeId);
                try
                {
                    this.database.ExecuteNonQuery(sqlStringCommand, dbTransaction);
                    this.database.ExecuteNonQuery(sqlStringCommand2, dbTransaction);
                    dbTransaction.Commit();
                    result = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    result = false;
                }
                finally
                {
                    if (dbTransaction.Connection != null)
                    {
                        dbConnection.Close();
                    }
                }
            }
            return(result);
        }
All Usage Examples Of System.Data.Common.DbTransaction::Commit