private static List <viewPageViewCount> SelectRows(string SQLString, Dictionary <Columns.ColumnNames, Object> ParameterDictionary) { List <viewPageViewCount> returnValue = new List <viewPageViewCount>(); using (SqlConnection connection = new SqlConnection(DBL.Lookups.GetConnString())) { using (SqlCommand Command = new SqlCommand(SQLString, connection)) { Command.CommandType = CommandType.Text; if (ParameterDictionary != null) { int i = 1; foreach (Columns.ColumnNames key in ParameterDictionary.Keys) { if (ParameterDictionary[key].GetType() == typeof(string)) //TODO: TEST THIS? { Command.Parameters.Add(new SqlParameter("@SearchValue" + i.ToString(), ParameterDictionary[key].ToString().Replace("*", "%"))); } else { Command.Parameters.Add(new SqlParameter("@SearchValue" + i.ToString(), ParameterDictionary[key])); } i += 1; } } connection.Open(); try { IDataReader dR = Command.ExecuteReader(); do { viewPageViewCount MyviewPageViewCount = new viewPageViewCount(0); if (dR[Columns.PageID] == DBNull.Value) { MyviewPageViewCount.PageID = (System.Int32)dR[Columns.PageID]; } if (dR[Columns.SumOfViewCount] == DBNull.Value) { MyviewPageViewCount.SumOfViewCount = (System.Int32)dR[Columns.SumOfViewCount]; } } while (dR.Read()); dR.Close(); dR = null; } catch (Exception ex) { System.Diagnostics.StackTrace ST = new System.Diagnostics.StackTrace(); System.Diagnostics.StackFrame SF = ST.GetFrame(0); // Current Method DBL.Errors.LogError(SF.GetMethod().ReflectedType.Name + ":" + SF.GetMethod().Name, ex.Message); } finally { connection.Close(); } } } return(returnValue); }
public static List <viewPageViewCount> SelectDynamicList(string WhereClause, string SortOrder, int NumRows) { List <viewPageViewCount> RetVal = new List <viewPageViewCount>(); using (SqlConnection connection = new SqlConnection(DBL.Lookups.GetConnString())) { string strSQL = "SELECT * " + NumRows + " FROM [viewPageViewCount]"; if (!WhereClause.Equals(null)) { strSQL += " WHERE " + WhereClause; } if (!SortOrder.Equals(null)) { strSQL += " ORDER BY " + SortOrder; } using (SqlCommand Command = new SqlCommand(strSQL, connection)) { Command.CommandType = CommandType.Text; connection.Open(); try { IDataReader dR = Command.ExecuteReader(); do { viewPageViewCount newRow = new viewPageViewCount(0); if (dR[Columns.PageID] != DBNull.Value) { newRow.PageID = (System.Int32)dR[Columns.PageID]; } if (dR[Columns.SumOfViewCount] != DBNull.Value) { newRow.SumOfViewCount = (System.Int32)dR[Columns.SumOfViewCount]; } RetVal.Add(newRow); } while (dR.Read()); dR.Close(); dR = null; } catch (Exception ex) { System.Diagnostics.StackTrace ST = new System.Diagnostics.StackTrace(); System.Diagnostics.StackFrame SF = ST.GetFrame(0); // Current Method DBL.Errors.LogError(SF.GetMethod().ReflectedType.Name + ":" + SF.GetMethod().Name, ex.Message); } finally { connection.Close(); } } } return(RetVal); }
public static List <viewPageViewCount> Search(IDictionary <string, Object> SearchValues) { List <viewPageViewCount> returnValue = new List <viewPageViewCount>(); using (SqlConnection connection = new SqlConnection(DBL.Lookups.GetConnString())) { string strSQL = "SELECT [PageID], [SumOfViewCount] FROM viewPageViewCount"; if (SearchValues.Count > 0) { strSQL += " WHERE "; int i = 1; foreach (string key in SearchValues.Keys) { if (SearchValues[key].GetType() == typeof(string)) { strSQL += key + " LIKE @" + key; } else { strSQL += key + " = @" + key; } if (i < SearchValues.Count) { strSQL += " AND "; } i += 1; } } using (SqlCommand Command = new SqlCommand(strSQL, connection)) { Command.CommandType = CommandType.Text; int i = 1; foreach (string key in SearchValues.Keys) { if (SearchValues[key].GetType() == typeof(string)) { Command.Parameters.Add(new SqlParameter("@SearchValue" + i.ToString(), SearchValues[key].ToString().Replace("*", "%"))); } else { Command.Parameters.Add(new SqlParameter("@SearchValue" + i.ToString(), SearchValues[key])); } i += 1; } connection.Open(); try { IDataReader dR = Command.ExecuteReader(); do { viewPageViewCount MyviewPageViewCount = new viewPageViewCount(0); if (dR[Columns.PageID] == DBNull.Value) { MyviewPageViewCount.PageID = (System.Int32)dR[Columns.PageID]; } if (dR[Columns.SumOfViewCount] == DBNull.Value) { MyviewPageViewCount.SumOfViewCount = (System.Int32)dR[Columns.SumOfViewCount]; } returnValue.Add(MyviewPageViewCount); } while (dR.Read()); dR.Close(); dR = null; } catch (Exception ex) { System.Diagnostics.StackTrace ST = new System.Diagnostics.StackTrace(); System.Diagnostics.StackFrame SF = ST.GetFrame(0); // Current Method DBL.Errors.LogError(SF.GetMethod().ReflectedType.Name + ":" + SF.GetMethod().Name, ex.Message); } finally { connection.Close(); } } } return(returnValue); }