Exemplo n.º 1
0
        public static int ExecuteNonQuery(string sqlStatement)
        {
            try {
                using (DatabaseContext context = DatabaseContext.GetContext()) {
                    SqlCommand sql_cmd = context.CreateCommand() as SqlCommand;
                    sql_cmd.CommandText = sqlStatement;

                    return(sql_cmd.ExecuteNonQuery());
                }
            } catch (Exception e) {
                LoggingAPI.ReportException(e);
                throw new Exception("Failed to execute non query SQL command...");
            }
        }
Exemplo n.º 2
0
        public static int ExecuteScalar(string sqlStatement)
        {
            try {
                using (DatabaseContext context = DatabaseContext.GetContext()) {
                    SqlCommand cmd = context.CreateCommand() as SqlCommand;

                    cmd.CommandText = sqlStatement;
                    Object result = cmd.ExecuteScalar();

                    return(Convert.ToInt32(result));
                }
            } catch (Exception e) {
                LoggingAPI.ReportException(e);
                throw new Exception("Failed to execute scalar SQL command...");
            }
        }
Exemplo n.º 3
0
        public static DataTable GetTable(string sqlStatement)
        {
            DataTable t = new DataTable();

            try {
                using (DatabaseContext context = DatabaseContext.GetContext()) {
                    SqlCommand cmdAllResources = context.CreateCommand() as SqlCommand;
                    cmdAllResources.CommandText = sqlStatement;

                    using (SqlDataReader r = cmdAllResources.ExecuteReader()) {
                        t.Load(r);
                    }
                }
                return(t);
            }
            catch (Exception e) {
                LoggingAPI.ReportException(e);
                throw new Exception("Failed to execute SQL command...");
            }
        }