public List <Classify> GetPageList(int start, int end) { string sql = "select * from(select *,row_number()over(order by id) as num from Classifys) as t where t.num between @start and @end"; SqlParameter[] ps = new SqlParameter[] { new SqlParameter("@start", start), new SqlParameter("@end", end), }; DataTable dt = DbHelper.GetDataTable(sql, ps); if (dt != null && dt.Rows.Count < 1) { return(null); } List <Model.Classify> models = new List <Model.Classify>(); for (int i = 0; i < dt.Rows.Count; ++i) { Model.Classify model = new Model.Classify(); model.Id = Convert.ToInt32(dt.Rows[i]["Id"].ToString()); model.ClassifyName = dt.Rows[i]["ClassifyName"].ToString(); models.Add(model); } return(models); }
public Classify GetModel(int id) { string sql = "select * from Classifys where Id=@id"; SqlParameter p = new SqlParameter("@id", id); DataTable dt = DbHelper.GetDataTable(sql, p); if (dt == null || dt.Rows.Count < 1) { return(null); } Model.Classify model = new Model.Classify(); model.Id = Convert.ToInt32(dt.Rows[0]["Id"].ToString()); model.ClassifyName = dt.Rows[0]["ClassifyName"].ToString(); return(model); }
/// <summary> /// 获得所有分类 /// </summary> /// <returns></returns> public List <Classify> GetAllList() { string sql = "select * from Classifys"; DataTable dt = DbHelper.GetDataTable(sql); if (dt == null || dt.Rows.Count < 1) { return(null); } List <Model.Classify> models = new List <Model.Classify>(); for (int i = 0; i < dt.Rows.Count; ++i) { Model.Classify model = new Model.Classify(); model.Id = Convert.ToInt32(dt.Rows[i]["Id"].ToString()); model.ClassifyName = dt.Rows[i]["ClassifyName"].ToString(); models.Add(model); } return(models); }