首页 > 代码库 > 用泛型做的分页类
用泛型做的分页类
/// <summary> /// 分页 /// </summary> /// <param name="num">每页的数量</param> /// <param name="page">页码</param> /// <param name="model">参数列表(用于查询)</param> /// <returns></returns> public static List<T> GetPagers(int num, int page, T model) { List<T> tList = new List<T>(); string name = new T().GetType().Name; PropertyInfo[] proList = model.GetType().GetProperties(); string sqlStr = "select top " + num + " * from " + name; string whereStr = " "; foreach (PropertyInfo pi in proList) { if (DbHelperSQL.IsPrimaryKey(pi.Name, name) == true) { sqlStr = sqlStr + " where " + pi.Name + " not in (select top (" + num + " * (" + page + "-1))" + pi.Name + " from " + name + " order by OrderDate desc)"; } } foreach (PropertyInfo pi in proList) { if (pi.GetValue(model, null) != null && DbHelperSQL.IsPrimaryKey(pi.Name, name) == false) { string piValue = http://www.mamicode.com/pi.GetValue(model, null).ToString();"False" && piValue != "0001/1/1 0:00:00" && piValue != "0") { whereStr += " and " + pi.Name + "=‘" + pi.GetValue(model, null).ToString() + "‘ order by OrderDate desc"; } } } string sql = sqlStr + whereStr; DataTable dt = DbHelperSQL.Query(sql).Tables[0]; foreach (DataRow dr in dt.Rows) { T t = new T(); PropertyInfo[] list = t.GetType().GetProperties(); foreach (PropertyInfo pi in list) { string piName = pi.Name; if (dt.Columns.Contains(piName)) { if (!pi.CanWrite) continue; object value = http://www.mamicode.com/dr[piName];>
用泛型做的分页类
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。