/// 执行非查询存储过程和SQL语句 /// 增、删、改 /// </summary> /// <param name="strSQL">要执行的SQL语句</param> /// <param name="paras">参数列表,没有参数填入null</param> /// <param name="cmdType">Command类型</param> /// <returns>返回影响行数</returns> public static int ExcuteSQL(string strSQL, SqlParameter[] paras, CommandType cmdType) { int i = 0; using (SqlConnection conn = new SqlConnection(strConn)) { try { SqlCommand cmd = new SqlCommand(strSQL, conn); cmd.CommandType = cmdType; if (paras != null) { cmd.Parameters.AddRange(paras); } conn.Open(); i = cmd.ExecuteNonQuery(); } catch (Exception ex) { WriteLog.WriteError(ex.Message); } finally { conn.Close(); } } return(i); }
/// <summary> /// 执行查询,返回DataTable对象 /// </summary> /// <param name="strSQL">sql语句</param> /// <param name="pas">参数数组</param> /// <param name="cmdtype">Command类型</param> /// <returns>DataTable对象</returns> public static DataTable GetTable(string strSQL, SqlParameter[] pas, CommandType cmdtype) { DataTable dt = new DataTable();; using (SqlConnection conn = new SqlConnection(strConn)) { try { SqlDataAdapter da = new SqlDataAdapter(strSQL, conn); da.SelectCommand.CommandType = cmdtype; if (pas != null) { da.SelectCommand.Parameters.AddRange(pas); } da.Fill(dt); } catch (Exception ex) { WriteLog.WriteError(ex.Message); } } return(dt); }
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { WriteLog.WriteError("Application_ThreadException:" + e.Exception.Message); }
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { WriteLog.WriteError("CurrentDomain_UnhandledException"); WriteLog.WriteError("IsTerminating : " + e.IsTerminating.ToString()); WriteLog.WriteError(e.ExceptionObject.ToString()); }