コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="connectionName"></param>
        /// <param name="commandText"></param>
        /// <param name="commandType"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public DataTable GetDataTable(string connectionName, string commandText, CommandType commandType, SqlParameter[] parameters)
        {
            using (var connection = dbConnectionHelper.GetConnection(connectionName))
            {
                try
                {
                    using (var command = connection.CreateCommand())
                    {
                        command.CommandText = commandText;
                        command.CommandType = commandType;
                        if (parameters != null)
                        {
                            foreach (var parameter in parameters)
                            {
                                command.Parameters.Add(parameter);
                            }
                        }

                        var dataSet = new DataSet();
                        var adapter = dbConnectionHelper.GetDbDataAdapter(command);
                        adapter.Fill(dataSet);

                        return(dataSet.Tables[0]);
                    }
                }
                catch (Exception ex)
                {
                    dbConnectionHelper.CloseConnection(connection);
                    exceptionHandling.LogException(ex, ExceptionPolicy.Web_Exception);
                    throw new Exception($"Error in {nameof(GetDataTable)}");
                }
            }
        }