コード例 #1
0
        /// <summary>
        /// Executes an insert/update/delete query and returns number of rows affected
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public int ExecuteNonQuery(string sql)
        {
            log.Debug("ExecuteNonQuery(sql): <div class='sql'>" + Preparer.Encode4Log(sql) + "</div>");
            MySqlCommand cmd = new MySqlCommand(sql, this.GetConnection());

            try
            {
                return(cmd.ExecuteNonQuery());
            }
            catch (Exception ex)
            {
                System.Diagnostics.StackFrame fr = new System.Diagnostics.StackFrame(1, true);
                System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(fr);
                log.Error("ExecuteNonQuery(sql): <div class='source'>" + Preparer.Encode4Log(st.ToString()) + "</div> <div class='message'>" + Preparer.Encode4Log(ex.Message) + "</div> <div class='sql'>" + Preparer.Encode4Log(sql) + "</div>");
                throw new Exception("ExecuteNonQuery was unable to execute the query.  Please tell the server administrator to review the error logs for details.");
            }
        }