/// <summary> /// Executes a SQL Query and returns the results as a SafeReader object /// </summary> /// <param name="SQLQuery">The Query to execute</param> /// <param name="PID">The Program ID that matches the configured connection string name</param> /// <returns></returns> public static SafeReader ExecuteSafeReader(string SQLQuery, string PID) { string cstr = ConfigurationManager.ConnectionStrings[PID].ToString(); using (SqlConnection cn = new SqlConnection(cstr)) { cn.Open(); using (SqlCommand cmd = new SqlCommand(SQLQuery, cn)) { cmd.CommandType = CommandType.Text; using (SqlDataReader dr = cmd.ExecuteReader()) { SafeReader sr = new SafeReader(dr); return(sr); } } } }
/// <summary> /// Returns data in a safe reader /// </summary> /// <param name="bo"></param> /// <remarks> /// [07/02/10] Created /// </remarks> public static SafeReader ExecuteSafeReader(string StoredProcName, SqlParameter[] Parameters, string PID) { string cstr = ConfigurationManager.ConnectionStrings[PID].ToString(); using (SqlConnection cn = new SqlConnection(cstr)) { cn.Open(); using (SqlCommand cmd = new SqlCommand(StoredProcName, cn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddRange(Parameters); using (SqlDataReader dr = cmd.ExecuteReader()) { SafeReader sr = new SafeReader(dr); return(sr); } } } }