Inheritance: MonoBehaviour
 /// <summary>
 /// 以 <paramref name="insertCommand"/>、<paramref name="insertCommand"/>、<paramref name="insertCommand"/> 作为数据处理命令更新 <paramref name="dataTable"/> 中的数据,并返回所影响的行数。
 /// </summary>
 /// <param name="database">表示一个 <see cref="Microsoft.Practices.EnterpriseLibrary.Data.Database"/> 对象。</param>
 /// <param name="dataTable">待更新数据的 <see cref="DataTable"/> 对象。</param>
 /// <param name="insertCommand">表示用于往数据表中插入数据的 <see cref="DbCommand"/> 对象。</param>
 /// <param name="updateCommand">表示用于往数据表中修改数据的 <see cref="DbCommand"/> 对象。</param>
 /// <param name="deleteCommand">表示用于往数据表中删除数据的 <see cref="DbCommand"/> 对象。</param>
 /// <param name="updateBehavior">一个 <see cref="UpdateBehavior"/> 值,用于控制执行 Update 操作时当出现错误时的事务处理机制。</param>
 /// <param name="updateBatchSize">该值启用或禁用批处理支持,并且指定可在一次批处理中执行的命令的数量。</param>
 /// <returns>表示脚本命令执行受影响的行数。</returns>
 public static int UpdateDataTable(this Database database, DataTable dataTable, DbCommand insertCommand, DbCommand updateCommand, DbCommand deleteCommand, UpdateBehavior updateBehavior, int? updateBatchSize)
 {
     using (var wrapper = GetOpenConnection(database))
     {
         if (updateBehavior == UpdateBehavior.Transactional && Transaction.Current == null)
         {
             DbTransaction transaction = wrapper.Connection.BeginTransaction();
             try
             {
                 int rowsAffected = UpdateDataTable(database, dataTable, transaction, insertCommand, updateCommand, deleteCommand, updateBatchSize);
                 transaction.Commit();
                 return rowsAffected;
             }
             catch
             {
                 transaction.Rollback();
                 throw;
             }
         }
         if (insertCommand != null)
         {
             PrepareCommand(insertCommand, wrapper.Connection);
         }
         if (updateCommand != null)
         {
             PrepareCommand(updateCommand, wrapper.Connection);
         }
         if (deleteCommand != null)
         {
             PrepareCommand(deleteCommand, wrapper.Connection);
         }
         return DoUpdateDataTable(database, dataTable,
                                insertCommand, updateCommand, deleteCommand, updateBehavior, updateBatchSize);
     }
 }
        /// <summary>
        /// <para>Create a <see cref="OleDbDataAdapter"/> with the given update behavior and connection.</para>
        /// </summary>
        /// <param name="updateBehavior">
        /// <para>One of the <see cref="UpdateBehavior"/> values.</para>
        /// </param>
        /// <param name="connection">
        /// <para>The open connection to the database.</para>
        /// </param>
        /// <returns>An <see cref="OleDbDataAdapter"/>.</returns>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="connection"/> can not be <see langword="null"/> (Nothing in Visual Basic).</para>
        /// </exception>
        protected virtual new DbDataAdapter GetDataAdapter(UpdateBehavior updateBehavior)
        {
            DbDataAdapter adapter = base.DbProviderFactory.CreateDataAdapter();

            this.SetUpRowUpdatedEvent(adapter);

            return(adapter);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Update DataSet with commands
        /// </summary>
        /// <param name="repository">IAdoRepository 인스턴스</param>
        /// <param name="dataSet">DataSet to update</param>
        /// <param name="tableName">table name to update</param>
        /// <param name="insertCommand">command to insert</param>
        /// <param name="updateCommand">command to update</param>
        /// <param name="deleteCommand">command to delete</param>
        /// <param name="updateBehavior">Behavior to update</param>
        /// <param name="updateBatchSize">batch size to update</param>
        /// <returns>affected row count</returns>
        public static int UpdateDataSet(this IAdoRepository repository,
                                        DataSet dataSet,
                                        string tableName,
                                        DbCommand insertCommand = null,
                                        DbCommand updateCommand = null,
                                        DbCommand deleteCommand = null,
                                        UpdateBehavior updateBehavior = UpdateBehavior.Transactional,
                                        int updateBatchSize = Int32.MaxValue) {
            dataSet.ShouldNotBeNull("dataSet");
            Guard.Assert(dataSet.Tables.Count > 0, "지정된 DataSet에 DataTable이 하나라도 있어야합니다.");

            if(tableName.IsWhiteSpace())
                tableName = dataSet.Tables[0].TableName;

            if(tableName.IsWhiteSpace())
                tableName = dataSet.Tables[0].TableName = Guid.NewGuid().ToString();

            if(repository.IsActiveTransaction) {
                if(IsDebugEnabled)
                    log.Debug("DataSet에 대해 Transaction 하에서 배치작업을 실행합니다... " +
                              "dataSet=[{0}], tableName=[{1}], insertCommand=[{2}], updateCommand=[{3}], deleteCommand=[{4}], ActiveTransaction=[{5}], updateBatchSize=[{6}]",
                              dataSet.DataSetName,
                              tableName,
                              insertCommand != null ? insertCommand.CommandText : "NULL",
                              updateCommand != null ? updateCommand.CommandText : "NULL",
                              deleteCommand != null ? deleteCommand.CommandText : "NULL",
                              repository.ActiveTransaction,
                              updateBatchSize);

                return repository.Db.UpdateDataSet(dataSet,
                                                   tableName,
                                                   insertCommand,
                                                   updateCommand,
                                                   deleteCommand,
                                                   repository.ActiveTransaction,
                                                   updateBatchSize);
            }

            if(IsDebugEnabled)
                log.Debug("DataSet에 대해 배치작업을 실행합니다... " +
                          "dataSet=[{0}], tableName=[{1}], insertCommand=[{2}], updateCommand=[{3}], deleteCommand=[{4}], ActiveTransaction=[{5}], updateBatchSize=[{6}]",
                          dataSet.DataSetName,
                          tableName,
                          insertCommand != null ? insertCommand.CommandText : "NULL",
                          updateCommand != null ? updateCommand.CommandText : "NULL",
                          deleteCommand != null ? deleteCommand.CommandText : "NULL",
                          repository.ActiveTransaction,
                          updateBatchSize);

            return repository.Db.UpdateDataSet(dataSet,
                                               tableName,
                                               insertCommand,
                                               updateCommand,
                                               deleteCommand,
                                               updateBehavior,
                                               updateBatchSize);
        }
Exemplo n.º 4
0
 /// <summary>
 /// <para>Create a <see cref="OracleDataAdapter"/> with the given update behavior and connection.</para>
 /// </summary>
 /// <param name="updateBehavior">
 /// <para>One of the <see cref="UpdateBehavior"/> values.</para>
 /// </param>
 /// <param name="connection">
 /// <para>The open connection to the database.</para>
 /// </param>
 /// <returns>An <see cref="OracleDataAdapter"/>.</returns>
 /// <exception cref="ArgumentNullException">
 /// <para><paramref name="connection"/> can not be <see langword="null"/> (Nothing in Visual Basic).</para>
 /// </exception>
 protected override DbDataAdapter GetDataAdapter(UpdateBehavior updateBehavior, IDbConnection connection)
 {
     OracleDataAccess.Client.OracleDataAdapter adapter = new OracleDataAccess.Client.OracleDataAdapter(String.Empty, (OracleDataAccess.Client.OracleConnection)connection);
     if (updateBehavior == UpdateBehavior.Continue)
     {
         adapter.RowUpdated += new OracleDataAccess.Client.OracleRowUpdatedEventHandler(OnOracleRowUpdated);
     }
     return(adapter);
 }
Exemplo n.º 5
0
 public int UpdateDataSet(
     DataSet dataSet,
     string tableName,
     DbCommand insertCommand,
     DbCommand updateCommand,
     DbCommand deleteCommand,
     UpdateBehavior updateBehavior)
 {
     return(this.a.UpdateDataSet(dataSet, tableName, insertCommand, updateCommand, deleteCommand, updateBehavior));
 }
Exemplo n.º 6
0
 public int UpdateDataSet(
     DataSet dataSet,
     string tableName,
     DbCommand insertCommand,
     DbCommand updateCommand,
     DbCommand deleteCommand,
     UpdateBehavior updateBehavior,
     int?updateBatchSize)
 {
     using (DatabaseConnectionWrapper openConnection = this.GetOpenConnection())
     {
         if (updateBehavior == UpdateBehavior.Transactional && Transaction.Current == (Transaction)null)
         {
             DbTransaction transaction = Database.BeginTransaction(openConnection.Connection);
             try
             {
                 int num = this.UpdateDataSet(dataSet, tableName, insertCommand, updateCommand, deleteCommand, transaction, updateBatchSize);
                 Database.CommitTransaction((IDbTransaction)transaction);
                 return(num);
             }
             catch
             {
                 Database.RollbackTransaction((IDbTransaction)transaction);
                 throw;
             }
         }
         else
         {
             if (insertCommand != null)
             {
                 Database.PrepareCommand(insertCommand, openConnection.Connection);
             }
             if (updateCommand != null)
             {
                 Database.PrepareCommand(updateCommand, openConnection.Connection);
             }
             if (deleteCommand != null)
             {
                 Database.PrepareCommand(deleteCommand, openConnection.Connection);
             }
             return(this.DoUpdateDataSet(updateBehavior, dataSet, tableName, (IDbCommand)insertCommand, (IDbCommand)updateCommand, (IDbCommand)deleteCommand, updateBatchSize));
         }
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// <para>Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the <see cref="DataSet"/>.</para>
        /// </summary>
        /// <param name="dataSet"><para>The <see cref="DataSet"/> used to update the data source.</para></param>
        /// <param name="tableName"><para>The name of the source table to use for table mapping.</para></param>
        /// <param name="insertCommand"><para>The <see cref="DBCommandWrapper"/> executed when <see cref="DataRowState"/> is <seealso cref="DataRowState.Added"/></para></param>
        /// <param name="updateCommand"><para>The <see cref="DBCommandWrapper"/> executed when <see cref="DataRowState"/> is <seealso cref="DataRowState.Modified"/></para></param>
        /// <param name="deleteCommand"><para>The <see cref="DBCommandWrapper"/> executed when <see cref="DataRowState"/> is <seealso cref="DataRowState.Deleted"/></para></param>
        /// <param name="updateBehavior"><para>One of the <see cref="UpdateBehavior"/> values.</para></param>
        /// <returns>number of records affected</returns>
        /// <seealso cref="DbDataAdapter.Update"/>
        public virtual int UpdateDataSet(DataSet dataSet, string tableName,
                                         DBCommandWrapper insertCommand, DBCommandWrapper updateCommand,
                                         DBCommandWrapper deleteCommand, UpdateBehavior updateBehavior)
        {
            using (IDbConnection connection = OpenConnection())
            {
                if (updateBehavior == UpdateBehavior.Transactional)
                {
                    IDbTransaction trans = BeginTransaction(connection);
                    try
                    {
                        int rowsAffected = UpdateDataSet(dataSet, tableName, insertCommand, updateCommand, deleteCommand, trans);
                        CommitTransaction(trans);
                        return(rowsAffected);
                    }
                    catch
                    {
                        RollbackTransaction(trans);
                        throw;
                    }
                }
                else
                {
                    if (insertCommand != null)
                    {
                        PrepareCommand(insertCommand, connection);
                    }
                    if (updateCommand != null)
                    {
                        PrepareCommand(updateCommand, connection);
                    }
                    if (deleteCommand != null)
                    {
                        PrepareCommand(deleteCommand, connection);
                    }

                    return(DoUpdateDataSet(updateBehavior, connection, dataSet, tableName,
                                           insertCommand, updateCommand, deleteCommand));
                }
            }
        }
Exemplo n.º 8
0
        private int DoUpdateDataSet(UpdateBehavior behavior, IDbConnection connection,
                                    DataSet dataSet, string tableName, DBCommandWrapper insertCommand,
                                    DBCommandWrapper updateCommand, DBCommandWrapper deleteCommand)
        {
            if (insertCommand == null && updateCommand == null && deleteCommand == null)
            {
                throw new ArgumentException("UpdateDataSetArgumentFailure");
            }

            using (DbDataAdapter adapter = GetDataAdapter(behavior, connection))
            {
                IDbDataAdapter explicitAdapter = (IDbDataAdapter)adapter;
                if (insertCommand != null)
                {
                    explicitAdapter.InsertCommand = insertCommand.Command;
                }
                if (updateCommand != null)
                {
                    explicitAdapter.UpdateCommand = updateCommand.Command;
                }
                if (deleteCommand != null)
                {
                    explicitAdapter.DeleteCommand = deleteCommand.Command;
                }

                try
                {
                    DateTime startTime = DateTime.Now;
                    int      rows      = adapter.Update(dataSet.Tables[tableName]);
                    return(rows);
                }
                catch
                {
                    throw;
                }
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// 批量Update
 /// </summary>
 /// <param name="behavior">更新行为</param>
 /// <param name="table">需要更新的数据表</param>
 /// <param name="updateCommand">更新数据DbCommand</param>
 /// <returns>影响行数</returns>
 public int BatchUpdate(UpdateBehavior behavior, DataTable table, DbCommand updateCommand)
 {
     return UpdateDataSet(behavior, table, null, updateCommand, null, null);
 }
Exemplo n.º 10
0
 private int DoUpdateDataSet(UpdateBehavior behavior, DataSet dataSet, string tableName, DbCommand insertCommand, DbCommand updateCommand, DbCommand deleteCommand)
 {
     int result;
     if (string.IsNullOrEmpty(tableName))
     {
         throw new ArgumentException("The value can not be null or an empty string", "tableName");
     }
     if (dataSet == null)
     {
         throw new ArgumentNullException("dataSet");
     }
     if (((insertCommand == null) && (updateCommand == null)) && (deleteCommand == null))
     {
         throw new ArgumentException("At least one command must be initialized");
     }
     using (DbDataAdapter adapter = this.GetDataAdapter(behavior))
     {
         if (insertCommand != null)
         {
             adapter.InsertCommand = insertCommand;
         }
         if (updateCommand != null)
         {
             adapter.UpdateCommand = updateCommand;
         }
         if (deleteCommand != null)
         {
             adapter.DeleteCommand = deleteCommand;
         }
         try
         {
             result = adapter.Update(dataSet.Tables[tableName]);
         }
         catch (Exception exception)
         {
             this.FireCommandFailedEvent("DbDataAdapter.Update() " + tableName, this.ConnectionStringNoCredentials, exception);
             throw;
         }
     }
     return result;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Gets the DbDataAdapter with the given update behavior and connection from the proper derived class.
        /// </summary>
        /// <param name="updateBehavior">
        /// <para>One of the <see cref="UpdateBehavior"/> values.</para>
        /// </param>        
        /// <returns>A <see cref="DbDataAdapter"/>.</returns>
        /// <seealso cref="DbDataAdapter"/>
        protected DbDataAdapter GetDataAdapter(UpdateBehavior updateBehavior)
        {
            DbDataAdapter adapter = dbProviderFactory.CreateDataAdapter();

            if (updateBehavior == UpdateBehavior.Continue)
            {
                SetUpRowUpdatedEvent(adapter);
            }
            return adapter;
        }
Exemplo n.º 12
0
 /// <summary>
 /// <para>Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the <see cref="DataSet"/>.</para>
 /// </summary>        
 /// <param name="dataSet"><para>The <see cref="DataSet"/> used to update the data source.</para></param>
 /// <param name="tableName"><para>The name of the source table to use for table mapping.</para></param>
 /// <param name="insertCommand"><para>The <see cref="DbCommand"/> executed when <see cref="DataRowState"/> is <seealso cref="DataRowState.Added"/></para></param>
 /// <param name="updateCommand"><para>The <see cref="DbCommand"/> executed when <see cref="DataRowState"/> is <seealso cref="DataRowState.Modified"/></para></param>        
 /// <param name="deleteCommand"><para>The <see cref="DbCommand"/> executed when <see cref="DataRowState"/> is <seealso cref="DataRowState.Deleted"/></para></param>        
 /// <param name="updateBehavior"><para>One of the <see cref="UpdateBehavior"/> values.</para></param>
 /// <returns>number of records affected</returns>        
 public int UpdateDataSet(DataSet dataSet,
                          string tableName,
                          DbCommand insertCommand,
                          DbCommand updateCommand,
                          DbCommand deleteCommand,
                          UpdateBehavior updateBehavior)
 {
     return UpdateDataSet(dataSet, tableName, insertCommand, updateCommand, deleteCommand, updateBehavior, null);
 }
 public override int UpdateDataSet(DataSet dataSet, string tableName, DbCommand insertCommand, DbCommand updateCommand, DbCommand deleteCommand, UpdateBehavior updateBehavior)
 {
     return(this.UpdateDataSetCore(dataSet, tableName, insertCommand, updateCommand, deleteCommand, updateBehavior, null));
 }
 public void UpdateDataSetWithOperator(DataSet dataSet, string tableName, DbCommand insertCommand, DbCommand updateCommand, DbCommand deleteCommand, UpdateBehavior updateBehavior, object dataOperator)
 {
     this.UpdateDataSetCore(dataSet, tableName, insertCommand, updateCommand, deleteCommand, updateBehavior, dataOperator);
 }
Exemplo n.º 15
0
 /// <summary>
 /// <para>When overridden in a derived class, creates a <see cref="DbDataAdapter"/> with the given update behavior and connection.</para>
 /// </summary>
 /// <param name="behavior">
 /// <para>One of the <see cref="UpdateBehavior"/> values.</para>
 /// </param>
 /// <param name="connection">
 /// <para>The open connection to the database.</para>
 /// </param>
 /// <returns>An <see cref="DbDataAdapter"/>.</returns>
 /// <seealso cref="DbDataAdapter"/>
 protected abstract DbDataAdapter GetDataAdapter(UpdateBehavior behavior, IDbConnection connection);
Exemplo n.º 16
0
        /// <summary>
        /// 批量更新
        /// </summary>
        /// <param name="behavior">更新行为</param>
        /// <param name="dataSet">待更新的数据</param>
        /// <param name="tableName">需要更新的数据表名称</param>
        /// <param name="insertCommand">增加数据DbCommand</param>
        /// <param name="updateCommand">更新数据DbCommand</param>
        /// <param name="deleteCommand">删除数据DbCommand</param>
        /// <param name="updateBatchSize">每批更新的数据量</param>
        /// <returns></returns>
        /// <remarks>
        ///     面向批量处理增加的方法
        ///     added by wangxiang . May 21, 2008
        /// </remarks>
        private int DoUpdateDataSet(UpdateBehavior behavior,
            DataSet dataSet,
            string tableName,
            DbCommand insertCommand,
            DbCommand updateCommand,
            DbCommand deleteCommand,
            int? updateBatchSize)
        {
            if (string.IsNullOrEmpty(tableName))
                throw new ArgumentNullException("tableName");
            if (dataSet == null)
                throw new ArgumentNullException("dataSet");

            return DoUpdateDataSet(behavior, dataSet.Tables[tableName], insertCommand, updateCommand, deleteCommand, updateBatchSize);
        }
Exemplo n.º 17
0
 /// <summary>
 /// <para>When overridden in a derived class, creates a <see cref="DbDataAdapter"/> with the given update behavior and connection.</para>        
 /// </summary>
 /// <param name="behavior">
 /// <para>One of the <see cref="UpdateBehavior"/> values.</para>
 /// </param>
 /// <param name="connection">
 /// <para>The open connection to the database.</para>
 /// </param>
 /// <returns>An <see cref="DbDataAdapter"/>.</returns>
 /// <seealso cref="DbDataAdapter"/>
 protected abstract DbDataAdapter GetDataAdapter(UpdateBehavior behavior, IDbConnection connection);
 /// <summary>
 /// 以 <paramref name="insertCommand"/>、<paramref name="insertCommand"/>、<paramref name="insertCommand"/> 作为数据处理命令更新 <paramref name="dataTable"/> 中的数据,并返回所影响的行数。
 /// </summary>
 /// <param name="database">表示一个 <see cref="Microsoft.Practices.EnterpriseLibrary.Data.Database"/> 对象。</param>
 /// <param name="dataTable">待更新数据的 <see cref="DataTable"/> 对象。</param>
 /// <param name="insertCommand">表示用于往数据表中插入数据的 <see cref="DbCommand"/> 对象。</param>
 /// <param name="updateCommand">表示用于往数据表中修改数据的 <see cref="DbCommand"/> 对象。</param>
 /// <param name="deleteCommand">表示用于往数据表中删除数据的 <see cref="DbCommand"/> 对象。</param>
 /// <param name="updateBehavior">一个 <see cref="UpdateBehavior"/> 值,用于控制执行 Update 操作时当出现错误时的事务处理机制。</param>
 /// <returns>表示脚本命令执行受影响的行数。</returns>
 public static int UpdateDataTable(this Database database, DataTable dataTable, DbCommand insertCommand, DbCommand updateCommand, DbCommand deleteCommand, UpdateBehavior updateBehavior)
 {
     return UpdateDataTable(database, dataTable, insertCommand, updateCommand, deleteCommand, UpdateBehavior.Standard, null);
 }
Exemplo n.º 19
0
        /// <summary>
        /// <para>Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the <see cref="DataSet"/>.</para>
        /// </summary>        
        /// <param name="dataSet"><para>The <see cref="DataSet"/> used to update the data source.</para></param>
        /// <param name="tableName"><para>The name of the source table to use for table mapping.</para></param>
        /// <param name="insertCommand"><para>The <see cref="DBCommandWrapper"/> executed when <see cref="DataRowState"/> is <seealso cref="DataRowState.Added"/></para></param>
        /// <param name="updateCommand"><para>The <see cref="DBCommandWrapper"/> executed when <see cref="DataRowState"/> is <seealso cref="DataRowState.Modified"/></para></param>        
        /// <param name="deleteCommand"><para>The <see cref="DBCommandWrapper"/> executed when <see cref="DataRowState"/> is <seealso cref="DataRowState.Deleted"/></para></param>        
        /// <param name="updateBehavior"><para>One of the <see cref="UpdateBehavior"/> values.</para></param>
        /// <returns>number of records affected</returns>
        /// <seealso cref="DbDataAdapter.Update"/>
        public virtual int UpdateDataSet(DataSet dataSet, string tableName,
                                         DBCommandWrapper insertCommand, DBCommandWrapper updateCommand,
                                         DBCommandWrapper deleteCommand, UpdateBehavior updateBehavior)
        {
            using (IDbConnection connection = OpenConnection())
            {
                if (updateBehavior == UpdateBehavior.Transactional)
                {
                    IDbTransaction trans = BeginTransaction(connection);
                    try
                    {
                        int rowsAffected = UpdateDataSet(dataSet, tableName, insertCommand, updateCommand, deleteCommand, trans);
                        CommitTransaction(trans);
                        return rowsAffected;
                    }
                    catch
                    {
                        RollbackTransaction(trans);
                        throw;
                    }
                }
                else
                {
                    if (insertCommand != null)
                    {
                        PrepareCommand(insertCommand, connection);
                    }
                    if (updateCommand != null)
                    {
                        PrepareCommand(updateCommand, connection);
                    }
                    if (deleteCommand != null)
                    {
                        PrepareCommand(deleteCommand, connection);
                    }

                    return DoUpdateDataSet(updateBehavior, connection, dataSet, tableName,
                                           insertCommand, updateCommand, deleteCommand);
                }
            }
        }
Exemplo n.º 20
0
        private int DoUpdateDataSet(UpdateBehavior behavior, IDbConnection connection,
                                    DataSet dataSet, string tableName, DBCommandWrapper insertCommand,
                                    DBCommandWrapper updateCommand, DBCommandWrapper deleteCommand)
        {
            ArgumentValidation.CheckForNullReference(dataSet, "dataSet");
            ArgumentValidation.CheckForNullReference(tableName, "tableName");
            ArgumentValidation.CheckForEmptyString(tableName, "tableName");

            if (insertCommand == null && updateCommand == null && deleteCommand == null)
            {
                throw new ArgumentException(SR.ExceptionMessageUpdateDataSetArgumentFailure);
            }

            using (DbDataAdapter adapter = GetDataAdapter(behavior, connection))
            {
                IDbDataAdapter explicitAdapter = (IDbDataAdapter) adapter;
                if (insertCommand != null)
                {
                    explicitAdapter.InsertCommand = insertCommand.Command;
                }
                if (updateCommand != null)
                {
                    explicitAdapter.UpdateCommand = updateCommand.Command;
                }
                if (deleteCommand != null)
                {
                    explicitAdapter.DeleteCommand = deleteCommand.Command;
                }

                try
                {
                    DateTime startTime = DateTime.Now;
                    int rows = adapter.Update(dataSet.Tables[tableName]);
                    this.instrumentation.CommandExecuted(startTime);
                    return rows;
                }
                catch
                {
                    this.instrumentation.CommandFailed("DbDataAdapter.Update() " + tableName, this.ConnectionStringNoCredentials);
                    throw;
                }
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// 批量更新
        /// </summary>
        /// <param name="behavior">更新行为</param>
        /// <param name="table">需要更新的数据表</param>
        /// <param name="insertCommand">增加数据DbCommand</param>
        /// <param name="updateCommand">更新数据DbCommand</param>
        /// <param name="deleteCommand">删除数据DbCommand</param>
        /// <param name="updateBatchSize">每批更新的数据量</param>
        /// <returns></returns>
        /// <remarks>
        ///     面向批量处理增加的方法
        ///     added by wangxiang . May 21, 2008
        /// </remarks>
        private int DoUpdateDataSet(UpdateBehavior behavior,
            DataTable table,
            DbCommand insertCommand,
            DbCommand updateCommand,
            DbCommand deleteCommand,
            int? updateBatchSize)
        {
            if (table == null)
                throw new ArgumentNullException("table");

            if (insertCommand == null && updateCommand == null && deleteCommand == null)
            {
                throw new ArgumentNullException("command");
            }

            using (DbDataAdapter adapter = GetDataAdapter(behavior))
            {
                IDbDataAdapter explicitAdapter = (IDbDataAdapter)adapter;

                if (insertCommand != null)
                {
                    explicitAdapter.InsertCommand = insertCommand;
                }
                if (updateCommand != null)
                {
                    explicitAdapter.UpdateCommand = updateCommand;
                }
                if (deleteCommand != null)
                {
                    explicitAdapter.DeleteCommand = deleteCommand;
                }

                if (updateBatchSize != null)
                {
                    adapter.UpdateBatchSize = (int)updateBatchSize;

                    if (insertCommand != null)
                        adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;

                    if (updateCommand != null)
                        adapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.None;

                    if (deleteCommand != null)
                        adapter.DeleteCommand.UpdatedRowSource = UpdateRowSource.None;
                }

                int rows = adapter.Update(table);

                return rows;
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Update DataSet with commands
        /// </summary>
        /// <param name="repository">IAdoRepository 인스턴스</param>
        /// <param name="dataSet">DataSet to update</param>
        /// <param name="tableName">table name to update</param>
        /// <param name="insertCommand">command to insert</param>
        /// <param name="updateCommand">command to update</param>
        /// <param name="deleteCommand">command to delete</param>
        /// <param name="updateBehavior">Behavior to update</param>
        /// <param name="updateBatchSize">batch size to update</param>
        /// <returns>affected row count</returns>
        public static int UpdateDataSet(this IAdoRepository repository,
                                        DataSet dataSet,
                                        string tableName,
                                        DbCommand insertCommand       = null,
                                        DbCommand updateCommand       = null,
                                        DbCommand deleteCommand       = null,
                                        UpdateBehavior updateBehavior = UpdateBehavior.Transactional,
                                        int updateBatchSize           = Int32.MaxValue)
        {
            dataSet.ShouldNotBeNull("dataSet");
            Guard.Assert(dataSet.Tables.Count > 0, "지정된 DataSet에 DataTable이 하나라도 있어야합니다.");

            if (tableName.IsWhiteSpace())
            {
                tableName = dataSet.Tables[0].TableName;
            }

            if (tableName.IsWhiteSpace())
            {
                tableName = dataSet.Tables[0].TableName = Guid.NewGuid().ToString();
            }

            if (repository.IsActiveTransaction)
            {
                if (IsDebugEnabled)
                {
                    log.Debug("DataSet에 대해 Transaction 하에서 배치작업을 실행합니다... " +
                              "dataSet=[{0}], tableName=[{1}], insertCommand=[{2}], updateCommand=[{3}], deleteCommand=[{4}], ActiveTransaction=[{5}], updateBatchSize=[{6}]",
                              dataSet.DataSetName,
                              tableName,
                              insertCommand != null ? insertCommand.CommandText : "NULL",
                              updateCommand != null ? updateCommand.CommandText : "NULL",
                              deleteCommand != null ? deleteCommand.CommandText : "NULL",
                              repository.ActiveTransaction,
                              updateBatchSize);
                }

                return(repository.Db.UpdateDataSet(dataSet,
                                                   tableName,
                                                   insertCommand,
                                                   updateCommand,
                                                   deleteCommand,
                                                   repository.ActiveTransaction,
                                                   updateBatchSize));
            }

            if (IsDebugEnabled)
            {
                log.Debug("DataSet에 대해 배치작업을 실행합니다... " +
                          "dataSet=[{0}], tableName=[{1}], insertCommand=[{2}], updateCommand=[{3}], deleteCommand=[{4}], ActiveTransaction=[{5}], updateBatchSize=[{6}]",
                          dataSet.DataSetName,
                          tableName,
                          insertCommand != null ? insertCommand.CommandText : "NULL",
                          updateCommand != null ? updateCommand.CommandText : "NULL",
                          deleteCommand != null ? deleteCommand.CommandText : "NULL",
                          repository.ActiveTransaction,
                          updateBatchSize);
            }

            return(repository.Db.UpdateDataSet(dataSet,
                                               tableName,
                                               insertCommand,
                                               updateCommand,
                                               deleteCommand,
                                               updateBehavior,
                                               updateBatchSize));
        }
Exemplo n.º 23
0
 /// <summary>
 /// 批量更新
 /// </summary>
 /// <param name="behavior">更新行为</param>
 /// <param name="dataSet">待更新的数据</param>
 /// <param name="tableName">需要更新的数据表名称</param>
 /// <param name="insertCommand">增加数据DbCommand</param>
 /// <param name="updateCommand">更新数据DbCommand</param>
 /// <param name="deleteCommand">删除数据DbCommand</param>
 /// <returns></returns>
 public int UpdateDataSet(UpdateBehavior behavior,
     DataSet dataSet,
     string tableName,
     DbCommand insertCommand,
     DbCommand updateCommand,
     DbCommand deleteCommand)
 {
     return DoUpdateDataSet(behavior, dataSet, tableName, insertCommand, updateCommand, deleteCommand, null);
 }
Exemplo n.º 24
0
 /// <summary>
 /// 批量更新
 /// </summary>
 /// <param name="behavior">更新行为</param>
 /// <param name="table">需要更新的数据表</param>
 /// <param name="insertCommand">增加数据DbCommand</param>
 /// <param name="updateCommand">更新数据DbCommand</param>
 /// <param name="deleteCommand">删除数据DbCommand</param>
 /// <returns></returns>
 public int UpdateDataSet(UpdateBehavior behavior,
     DataTable table,
     DbCommand insertCommand,
     DbCommand updateCommand,
     DbCommand deleteCommand)
 {
     return DoUpdateDataSet(behavior, table, insertCommand, updateCommand, deleteCommand, null);
 }
Exemplo n.º 25
0
 /// <summary>
 /// 批量Delete
 /// </summary>
 /// <param name="behavior">更新行为</param>
 /// <param name="table">需要更新的数据表</param>
 /// <param name="BatchDelete">BatchDeleteDbCommand</param>
 /// <returns>影响行数</returns>
 public int BatchDelete(UpdateBehavior behavior, DataTable table, DbCommand BatchDelete)
 {
     return UpdateDataSet(behavior, table, null, null, BatchDelete, null);
 }
Exemplo n.º 26
0
 private int DoUpdateDataSet(UpdateBehavior behavior, DataSet dataSet, string tableName, DbCommand insertCommand, DbCommand updateCommand, DbCommand deleteCommand, int? updateBatchSize)
 {
     int num2;
     if (string.IsNullOrEmpty(tableName))
     {
         throw new ArgumentException(Resources.ExceptionNullOrEmptyString, "tableName");
     }
     if (dataSet == null)
     {
         throw new ArgumentNullException("dataSet");
     }
     if (((insertCommand == null) && (updateCommand == null)) && (deleteCommand == null))
     {
         throw new ArgumentException(Resources.ExceptionMessageUpdateDataSetArgumentFailure);
     }
     using (DbDataAdapter adapter = this.GetDataAdapter(behavior))
     {
         IDbDataAdapter adapter2 = adapter;
         if (insertCommand != null)
         {
             adapter2.InsertCommand = insertCommand;
         }
         if (updateCommand != null)
         {
             adapter2.UpdateCommand = updateCommand;
         }
         if (deleteCommand != null)
         {
             adapter2.DeleteCommand = deleteCommand;
         }
         if (updateBatchSize.HasValue)
         {
             adapter.UpdateBatchSize = updateBatchSize.Value;
             if (insertCommand != null)
             {
                 adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
             }
             if (updateCommand != null)
             {
                 adapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.None;
             }
             if (deleteCommand != null)
             {
                 adapter.DeleteCommand.UpdatedRowSource = UpdateRowSource.None;
             }
         }
         try
         {
             DateTime now = DateTime.Now;
             int num = adapter.Update(dataSet.Tables[tableName]);
             this.instrumentationProvider.FireCommandExecutedEvent(now);
             return num;
         }
         catch (Exception exception)
         {
             this.instrumentationProvider.FireCommandFailedEvent("DbDataAdapter.Update() " + tableName, this.ConnectionStringNoCredentials, exception);
             throw;
         }
     }
     return num2;
 }
Exemplo n.º 27
0
 public int UpdateDataSet(DataSet dataSet, string tableName, DbCommand insertCommand, DbCommand updateCommand, DbCommand deleteCommand, UpdateBehavior updateBehavior, int? updateBatchSize)
 {
     using (ConnectionWrapper wrapper = this.GetOpenConnection())
     {
         if ((updateBehavior == UpdateBehavior.Transactional) && (Transaction.Current == null))
         {
             DbTransaction transaction = this.BeginTransaction(wrapper.Connection);
             try
             {
                 int num = this.UpdateDataSet(dataSet, tableName, insertCommand, updateCommand, deleteCommand, transaction, updateBatchSize);
                 this.CommitTransaction(transaction);
                 return num;
             }
             catch
             {
                 this.RollbackTransaction(transaction);
                 throw;
             }
         }
         if (insertCommand != null)
         {
             PrepareCommand(insertCommand, wrapper.Connection);
         }
         if (updateCommand != null)
         {
             PrepareCommand(updateCommand, wrapper.Connection);
         }
         if (deleteCommand != null)
         {
             PrepareCommand(deleteCommand, wrapper.Connection);
         }
         return this.DoUpdateDataSet(updateBehavior, dataSet, tableName, insertCommand, updateCommand, deleteCommand, updateBatchSize);
     }
 }
Exemplo n.º 28
0
        /// <summary>
        /// <para>Create a <see cref="OracleDataAdapter"/> with the given update behavior and connection.</para>
        /// </summary>
        /// <param name="updateBehavior">
        /// <para>One of the <see cref="UpdateBehavior"/> values.</para>
        /// </param>
        /// <param name="connection">
        /// <para>The open connection to the database.</para>
        /// </param>
        /// <returns>An <see cref="OracleDataAdapter"/>.</returns>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="connection"/> can not be <see langword="null"/> (Nothing in Visual Basic).</para>
        /// </exception>
        protected override DbDataAdapter GetDataAdapter(UpdateBehavior updateBehavior, IDbConnection connection)
        {
            ArgumentValidation.CheckForNullReference(connection, "connection");

             OracleDataAdapter adapter = new OracleDataAdapter(String.Empty, (OracleConnection)connection);
             if (updateBehavior == UpdateBehavior.Continue)
             {
            adapter.RowUpdated += new OracleRowUpdatedEventHandler(OnSybaseRowUpdated);
             }
             return adapter;
        }
Exemplo n.º 29
0
 public TestbedController(TestbedModel argModel, UpdateBehavior behavior,
     MouseBehavior mouseBehavior, TestbedErrorHandler errorHandler)
 {
     model = argModel;
     inputQueue = new LinkedList<QueueItem>();
     setFrameRate(DEFAULT_FPS);
     //animator = new Thread(s => run());
     updateBehavior = behavior;
     this.errorHandler = errorHandler;
     this.mouseBehavior = mouseBehavior;
     addListeners();
 }
 private int UpdateDataSetCore(DataSet dataSet, string tableName, DbCommand insertCommand, DbCommand updateCommand, DbCommand deleteCommand, UpdateBehavior updateBehavior, object dataOperator)
 {
     this.SetDataOperator(dataSet, tableName, dataOperator);
     this.SetDataOrganizationId(dataSet, tableName);
     if (insertCommand != null)
     {
         this.AddFixedParameter(insertCommand);
     }
     if (updateCommand != null)
     {
         this.AddFixedParameter(updateCommand);
     }
     if (deleteCommand != null)
     {
         this.AddFixedParameter(deleteCommand);
     }
     return(base.UpdateDataSet(dataSet, tableName, insertCommand, updateCommand, deleteCommand, updateBehavior));
 }
 /// <summary>
 /// 以 <paramref name="insertCommand"/>、<paramref name="insertCommand"/>、<paramref name="insertCommand"/> 作为数据处理命令更新 <paramref name="dataSet"/> 中特定名称的表的数据,并返回所影响的行数。
 /// </summary>
 /// <param name="database">表示一个 <see cref="Microsoft.Practices.EnterpriseLibrary.Data.Database"/> 对象。</param>
 /// <param name="dataSet">待更新数据的 <see cref="DataSet"/> 对象。</param>
 /// <param name="tableName">指示 <paramref name="dataSet"/> 中待更新的数据表的名称。</param>
 /// <param name="insertCommand">表示用于往数据表中插入数据的 <see cref="DbCommand"/> 对象。</param>
 /// <param name="updateCommand">表示用于往数据表中修改数据的 <see cref="DbCommand"/> 对象。</param>
 /// <param name="deleteCommand">表示用于往数据表中删除数据的 <see cref="DbCommand"/> 对象。</param>
 /// <param name="updateBatchSize">该值启用或禁用批处理支持,并且指定可在一次批处理中执行的命令的数量。</param>
 /// <param name="updateBehavior">一个 <see cref="UpdateBehavior"/> 值,用于控制执行 Update 操作时当出现错误时的事务处理机制。</param>
 /// <returns>表示脚本命令执行受影响的行数。</returns>
 public static int UpdateDataSet(Database database, DataSet dataSet, string tableName, DbCommand insertCommand, DbCommand updateCommand, DbCommand deleteCommand, UpdateBehavior updateBehavior, int? updateBatchSize)
 {
     return database.UpdateDataSet(dataSet, tableName, insertCommand, updateCommand, deleteCommand, updateBehavior, updateBatchSize);
 }
Exemplo n.º 32
0
        int DoUpdateDataSet(UpdateBehavior behavior,
                            DataSet dataSet,
                            string tableName,
                            IDbCommand insertCommand,
                            IDbCommand updateCommand,
                            IDbCommand deleteCommand,
                            int? updateBatchSize)
        {
            if (string.IsNullOrEmpty(tableName)) throw new ArgumentException(Resources.ExceptionNullOrEmptyString, "tableName");
            if (dataSet == null) throw new ArgumentNullException("dataSet");

            if (insertCommand == null && updateCommand == null && deleteCommand == null)
            {
                throw new ArgumentException(Resources.ExceptionMessageUpdateDataSetArgumentFailure);
            }

            using (DbDataAdapter adapter = GetDataAdapter(behavior))
            {
                IDbDataAdapter explicitAdapter = adapter;
                if (insertCommand != null)
                {
                    explicitAdapter.InsertCommand = insertCommand;
                }
                if (updateCommand != null)
                {
                    explicitAdapter.UpdateCommand = updateCommand;
                }
                if (deleteCommand != null)
                {
                    explicitAdapter.DeleteCommand = deleteCommand;
                }

                if (updateBatchSize != null)
                {
                    adapter.UpdateBatchSize = (int)updateBatchSize;
                    if (insertCommand != null)
                        adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
                    if (updateCommand != null)
                        adapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.None;
                    if (deleteCommand != null)
                        adapter.DeleteCommand.UpdatedRowSource = UpdateRowSource.None;
                }

                try
                {
                    DateTime startTime = DateTime.Now;
                    int rows = adapter.Update(dataSet.Tables[tableName]);
                    instrumentationProvider.FireCommandExecutedEvent(startTime);
                    return rows;
                }
                catch (Exception e)
                {
                    instrumentationProvider.FireCommandFailedEvent("DbDataAdapter.Update() " + tableName, ConnectionStringNoCredentials, e);
                    throw;
                }
            }
        }
Exemplo n.º 33
0
 /// <summary>
 /// Updates the dataset
 /// </summary>
 /// <param name="dataSet">The dataset</param>
 /// <param name="tableName">The tablename</param>
 /// <param name="insertCommand">The insert command</param>
 /// <param name="updateCommand">The update command</param>
 /// <param name="deleteCommand">The delete command</param>
 /// <param name="updateBehavior">The update behavior</param>
 /// <returns>The number of records affected</returns>
 public int UpdateDataSet(DataSet dataSet, string tableName, DbCommand insertCommand, DbCommand updateCommand, DbCommand deleteCommand, UpdateBehavior updateBehavior)
 {
     // TODO: MAKE USE OF PERSISTENT CONNECTION IF AVAILABLE
     using (DbConnection connection = this.OpenConnection())
     {
         if (updateBehavior == UpdateBehavior.Transactional)
         {
             DbTransaction transaction = this.BeginTransaction(connection);
             try
             {
                 int num = this.UpdateDataSet(dataSet, tableName, insertCommand, updateCommand, deleteCommand, transaction);
                 this.CommitTransaction(transaction);
                 return num;
             }
             catch
             {
                 this.RollbackTransaction(transaction);
                 throw;
             }
         }
         if (insertCommand != null)
         {
             PrepareCommand(insertCommand, connection);
         }
         if (updateCommand != null)
         {
             PrepareCommand(updateCommand, connection);
         }
         if (deleteCommand != null)
         {
             PrepareCommand(deleteCommand, connection);
         }
         return this.DoUpdateDataSet(updateBehavior, dataSet, tableName, insertCommand, updateCommand, deleteCommand);
     }
 }
Exemplo n.º 34
0
        /// <summary>
        /// <para>Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated, or deleted row in the <see cref="DataSet"/>.</para>
        /// </summary>        
        /// <param name="dataSet"><para>The <see cref="DataSet"/> used to update the data source.</para></param>
        /// <param name="tableName"><para>The name of the source table to use for table mapping.</para></param>
        /// <param name="insertCommand"><para>The <see cref="DbCommand"/> executed when <see cref="DataRowState"/> is <seealso cref="DataRowState.Added"/></para></param>
        /// <param name="updateCommand"><para>The <see cref="DbCommand"/> executed when <see cref="DataRowState"/> is <seealso cref="DataRowState.Modified"/></para></param>        
        /// <param name="deleteCommand"><para>The <see cref="DbCommand"/> executed when <see cref="DataRowState"/> is <seealso cref="DataRowState.Deleted"/></para></param>        
        /// <param name="updateBehavior"><para>One of the <see cref="UpdateBehavior"/> values.</para></param>
        /// <param name="updateBatchSize">The number of database commands to execute in a batch.</param>
        /// <returns>number of records affected</returns>        
        public int UpdateDataSet(DataSet dataSet,
                                 string tableName,
                                 DbCommand insertCommand,
                                 DbCommand updateCommand,
                                 DbCommand deleteCommand,
                                 UpdateBehavior updateBehavior,
                                 int? updateBatchSize)
        {
            using (var wrapper = GetOpenConnection())
            {
                if (updateBehavior == UpdateBehavior.Transactional && Transaction.Current == null)
                {
                    DbTransaction transaction = BeginTransaction(wrapper.Connection);
                    try
                    {
                        int rowsAffected = UpdateDataSet(dataSet, tableName, insertCommand, updateCommand, deleteCommand, transaction, updateBatchSize);
                        CommitTransaction(transaction);
                        return rowsAffected;
                    }
                    catch
                    {
                        RollbackTransaction(transaction);
                        throw;
                    }
                }

                if (insertCommand != null)
                {
                    PrepareCommand(insertCommand, wrapper.Connection);
                }
                if (updateCommand != null)
                {
                    PrepareCommand(updateCommand, wrapper.Connection);
                }
                if (deleteCommand != null)
                {
                    PrepareCommand(deleteCommand, wrapper.Connection);
                }

                return DoUpdateDataSet(updateBehavior, dataSet, tableName,
                                       insertCommand, updateCommand, deleteCommand, updateBatchSize);
            }
        }
Exemplo n.º 35
0
 /// <summary>
 /// Gets a data adapter with the specified update behavior
 /// </summary>
 /// <param name="updateBehavior">The update behavior</param>
 /// <returns>A new DbDataAdapter</returns>
 protected DbDataAdapter GetDataAdapter(UpdateBehavior updateBehavior)
 {
     DbDataAdapter adapter = this.DbProviderCreateDataAdapter();
     if (updateBehavior == UpdateBehavior.Continue)
     {
         this.SetUpRowUpdatedEvent(adapter);
     }
     return adapter;
 }
Exemplo n.º 36
0
        int DoUpdateDataSet(UpdateBehavior behavior,
                            DataSet dataSet,
                            string tableName,
                            IDbCommand insertCommand,
                            IDbCommand updateCommand,
                            IDbCommand deleteCommand,
                            int? updateBatchSize)
        {
            if (string.IsNullOrEmpty(tableName)) throw new ArgumentException(Resources.ExceptionNullOrEmptyString, "tableName");
            if (dataSet == null) throw new ArgumentNullException("dataSet");

            if (insertCommand == null && updateCommand == null && deleteCommand == null)
            {
                throw new ArgumentException(Resources.ExceptionMessageUpdateDataSetArgumentFailure);
            }

            using (DbDataAdapter adapter = GetDataAdapter(behavior))
            {
                IDbDataAdapter explicitAdapter = adapter;
                if (insertCommand != null)
                {
                    explicitAdapter.InsertCommand = insertCommand;
                }
                if (updateCommand != null)
                {
                    explicitAdapter.UpdateCommand = updateCommand;
                }
                if (deleteCommand != null)
                {
                    explicitAdapter.DeleteCommand = deleteCommand;
                }

                if (updateBatchSize != null)
                {
                    adapter.UpdateBatchSize = (int)updateBatchSize;
                    if (insertCommand != null)
                        adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
                    if (updateCommand != null)
                        adapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.None;
                    if (deleteCommand != null)
                        adapter.DeleteCommand.UpdatedRowSource = UpdateRowSource.None;
                }

                int rows = adapter.Update(dataSet.Tables[tableName]);
                return rows;
            }
        }
Exemplo n.º 37
0
 /// <summary>
 /// 批量Insert
 /// </summary>
 /// <param name="behavior">更新行为</param>
 /// <param name="table">需要更新的数据表</param>
 /// <param name="insertCommand">增加数据DbCommand</param>
 /// <returns>影响行数</returns>
 public int BatchInsert(UpdateBehavior behavior, DataTable table, DbCommand insertCommand)
 {
     return UpdateDataSet(behavior, table, insertCommand, null, null, null);
 }
Exemplo n.º 38
0
        /// <summary>
        /// <para>Create a <see cref="SqlDataAdapter"/> with the given update behavior and connection.</para>
        /// </summary>
        /// <param name="updateBehavior">
        /// <para>One of the <see cref="UpdateBehavior"/> values.</para>
        /// </param>
        /// <param name="connection">
        /// <para>The open connection to the database.</para>
        /// </param>
        /// <returns>An <see cref="SqlDataAdapter"/>.</returns>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="connection"/> can not be <see langword="null"/> (Nothing in Visual Basic).</para>
        /// </exception>
        protected override DbDataAdapter GetDataAdapter(UpdateBehavior updateBehavior, IDbConnection connection)
        {
            string queryStringToBeFilledInLater = String.Empty;
            SqlDataAdapter adapter = new SqlDataAdapter(queryStringToBeFilledInLater, (SqlConnection)connection);

            if (updateBehavior == UpdateBehavior.Continue)
            {
                adapter.RowUpdated += new SqlRowUpdatedEventHandler(OnSqlRowUpdated);
            }
            return adapter;
        }
 /// <summary>
 /// 以 <paramref name="insertCommand"/>、<paramref name="insertCommand"/>、<paramref name="insertCommand"/> 作为数据处理命令更新 <paramref name="dataTable"/> 中的数据,并返回所影响的行数。
 /// </summary>
 /// <param name="database">表示一个 <see cref="Microsoft.Practices.EnterpriseLibrary.Data.Database"/> 对象。</param>
 /// <param name="dataTable">待更新数据的 <see cref="DataTable"/> 对象。</param>
 /// <param name="insertCommand">表示用于往数据表中插入数据的 <see cref="DbCommand"/> 对象。</param>
 /// <param name="updateCommand">表示用于往数据表中修改数据的 <see cref="DbCommand"/> 对象。</param>
 /// <param name="deleteCommand">表示用于往数据表中删除数据的 <see cref="DbCommand"/> 对象。</param>
 /// <param name="updateBehavior">一个 <see cref="UpdateBehavior"/> 值,用于控制执行 Update 操作时当出现错误时的事务处理机制。</param>
 /// <param name="updateBatchSize">该值启用或禁用批处理支持,并且指定可在一次批处理中执行的命令的数量。</param>
 /// <returns>表示脚本命令执行受影响的行数。</returns>
 public static int UpdateDataTable(this Database database, DataTable dataTable, DbCommand insertCommand, DbCommand updateCommand, DbCommand deleteCommand, UpdateBehavior updateBehavior, int?updateBatchSize)
 {
     using (var wrapper = GetOpenConnection(database))
     {
         if (updateBehavior == UpdateBehavior.Transactional && Transaction.Current == null)
         {
             DbTransaction transaction = wrapper.Connection.BeginTransaction();
             try
             {
                 int rowsAffected = UpdateDataTable(database, dataTable, transaction, insertCommand, updateCommand, deleteCommand, updateBatchSize);
                 transaction.Commit();
                 return(rowsAffected);
             }
             catch
             {
                 transaction.Rollback();
                 throw;
             }
         }
         if (insertCommand != null)
         {
             PrepareCommand(insertCommand, wrapper.Connection);
         }
         if (updateCommand != null)
         {
             PrepareCommand(updateCommand, wrapper.Connection);
         }
         if (deleteCommand != null)
         {
             PrepareCommand(deleteCommand, wrapper.Connection);
         }
         return(DoUpdateDataTable(database, dataTable,
                                  insertCommand, updateCommand, deleteCommand, updateBehavior, updateBatchSize));
     }
 }