private IEnumerable<Model.SearchSum> DoSelect() { DataTable dt = SqlHelper.ExecuteDataTable(@" select top 5 Keyword,count(*) as searchcount from keywords where datediff(day,searchdatetime,getdate())<7 group by Keyword order by count(*) desc "); List<Model.SearchSum> list = new List<Model.SearchSum>(); if (dt!=null&&dt.Rows!=null&&dt.Rows.Count>0) { foreach (DataRow row in dt.Rows) { Model.SearchSum oneModel=new Model.SearchSum (); oneModel.Keyword = Convert.ToString(row["keyword"]); oneModel.SearchCount = Convert.ToInt32(row["SearchCount"]); list.Add(oneModel); } } return list; }
public IEnumerable<Model.SearchSum> GetSuggestion(string kw) { DataTable dt = SqlHelper.ExecuteDataTable(@"select top 5 Keyword,count(*) as searchcount from keywords where datediff(day,searchdatetime,getdate())<7 and keyword like @keyword group by Keyword order by count(*) desc",new SqlParameter("@keyword","%"+kw+"%")); List<Model.SearchSum> list = new List<Model.SearchSum>(); if (dt != null && dt.Rows != null && dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { Model.SearchSum oneModel = new Model.SearchSum(); oneModel.Keyword = Convert.ToString(row["keyword"]); oneModel.SearchCount = Convert.ToInt32(row["SearchCount"]); list.Add(oneModel); } } return list; }