Exemple #1
0
        /// <summary>
        /// Get a Sql Command instance.
        /// Transaction is added if available.
        /// </summary>
        /// <param name="commandBuilder">Command to set in the Sql Command instance.</param>
        /// <returns> The Sql Command instance.</returns>
        protected SqlCommand GetCommand(SqlCommandBuilder commandBuilder)
        {
            SqlCommand command;

            if (commandBuilder.IsSqlParameterUsed)
            {
                if (_transaction.IsNull())
                {
                    command = new SqlCommand(null, Connection);
                }
                else
                {
                    command = new SqlCommand(null, Connection, _transaction);
                }

                command.Parameters.AddRange(commandBuilder.GetSqlParameters().ToArray());
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = commandBuilder.StoredProcedureName;
            }
            else
            {
                if (_transaction.IsNull())
                {
                    command = new SqlCommand(commandBuilder.GetCommand(), Connection);
                }
                else
                {
                    command = new SqlCommand(commandBuilder.GetCommand(), Connection, _transaction);
                }
            }

            command.CommandTimeout = CommandTimeout;
            return(command);
        }