Esempio n. 1
0
        /// <summary>
        /// Query the database to get a single value
        /// </summary>
        /// <typeparam name="T">Return type</typeparam>
        /// <param name="EstablishedConnection">An open and established connection to a MySQL database</param>
        /// <param name="QueryString">SQL query to retrieve the value requested</param>
        /// <param name="Parameters">Dictionary of named parameters</param>
        /// <param name="ThrowException">Throw exception or swallow and return default(T)</param>
        /// <returns>Single value of type T</returns>
        internal static T GetScalar <T>(MySqlConnection EstablishedConnection, string QueryString, Dictionary <string, object> Parameters = null, bool ThrowException = true, MySqlTransaction SqlTransaction = null)
        {
            return(DatabaseWorkHelper.DoDatabaseWork <T>(EstablishedConnection, QueryString,
                                                         (cmd) =>
            {
                cmd.Parameters.AddAllParameters(Parameters);

                var scalarResult = cmd.ExecuteScalar();

                return DatabaseCoreUtilities.ConvertScalar <T>(scalarResult);
            },
                                                         ThrowException: ThrowException, UseTransaction: SqlTransaction != null, SqlTransaction: SqlTransaction));
        }
Esempio n. 2
0
        internal static DataTable GetDataTable(MySqlConnection EstablishedConnection, string QueryString, Dictionary <string, object> Parameters = null, bool ThrowException = true, MySqlTransaction SqlTransaction = null)
        {
            return(DatabaseWorkHelper.DoDatabaseWork <DataTable>(EstablishedConnection, QueryString,
                                                                 (cmd) =>
            {
                cmd.Parameters.AddAllParameters(Parameters);

                using (var tableAdapter = new MySqlDataAdapter())
                {
                    tableAdapter.SelectCommand = cmd;
                    tableAdapter.SelectCommand.CommandType = CommandType.Text;

                    var outputTable = new DataTable();
                    tableAdapter.Fill(outputTable);

                    return outputTable;
                }
            }, ThrowException: ThrowException, UseTransaction: SqlTransaction != null, SqlTransaction: SqlTransaction));
        }