예제 #1
0
        private void PrepareCommand(IDbCommand command, IDbConnection
                                    connection,
                                    IDbTransaction transaction, CommandType commandType, string
                                    commandText,
                                    IDbDataParameter[] commandParameters, CommandBuilderType commandBuilderType = CommandBuilderType.NONE)
        {
            command.Connection  = connection;
            command.CommandText = commandText;
            command.CommandType = commandType;

            if (transaction != null)
            {
                command.Transaction = transaction;
            }

            if (commandParameters != null)
            {
                AttachParameters(command, commandParameters);
            }

            if (iDbCommandBuilder != null)
            {
                switch (commandBuilderType)
                {
                case CommandBuilderType.InsertCommand:
                    iDbCommandBuilder.GetInsertCommand();
                    break;

                case CommandBuilderType.DeleteCommand:
                    iDbCommandBuilder.GetDeleteCommand();
                    break;

                case CommandBuilderType.UpdateCommand:
                    iDbCommandBuilder.GetUpdateCommand();
                    break;

                case CommandBuilderType.InsertUpdateCommand:
                    iDbCommandBuilder.GetInsertCommand();
                    iDbCommandBuilder.GetUpdateCommand();
                    break;

                case CommandBuilderType.NONE:
                    break;

                default:
                    break;
                }
            }
        }
예제 #2
0
 public void BulkUpdateByDataSet(CommandType commandType, string commandText, DataTable ds, CommandBuilderType commandBuilderType = CommandBuilderType.NONE)
 {
     try
     {
         IDbDataAdapter dataAdapter = CreateCommandAndDataAdapter();
         GetTheCommandBuilder(dataAdapter);
         dataAdapter.SelectCommand = this.idbCommand;
         PrepareCommand(idbCommand, this.Connection, this.Transaction, commandType, commandText, this.Parameters, commandBuilderType);
         BuildInsertCommandForCommandBuilder();
         dataAdapter.SelectCommand = idbCommand;
         DataSet dataSet = new DataSet();
         dataSet.Tables.Add(ds.Copy());
         dataAdapter.Update(dataSet);
         idbCommand.Parameters.Clear();
     }
     catch (Exception)
     {
         throw;
     }
 }