首页 > 代码库 > 数据分页

数据分页

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#region 数据分页 返回 DataTable
        /// <summary>
        /// 摘要:
        ///     数据分页
        /// 参数:
        ///     sql:传入要执行sql语句
        ///     param:参数化
        ///     orderField:排序字段
        ///     orderType:排序类型
        ///     pageIndex:当前页
        ///     pageSize:页大小
        ///     count:返回查询条数
        /// </summary>
        public DataTable GetPageList(string sql, SqlParam[] param, string orderField, string orderType, int pageIndex, int pageSize, ref int count)
        {
            StringBuilder sb = new StringBuilder();
            try
            {
                int num = (pageIndex - 1) * pageSize;
                int num1 = (pageIndex) * pageSize;
                sb.Append("Select * From (Select ROW_NUMBER() Over (Order By " + orderField + " " + orderType + "");
                sb.Append(") As rowNum, * From (" + sql + ") As T ) As N Where rowNum > " + num + " And rowNum <= " + num1 + "");
                count = Convert.ToInt32(this.GetObjectValue(new StringBuilder("Select Count(1) From (" + sql + ") As t"), param));
                return this.GetDataTableBySQL(sb, param);
            }
            catch (Exception e)
            {
                DbLog.WriteException(e);
                return null; ;
            }
        }
        /// <summary>
        /// 摘要:
        ///     数据分页
        /// 参数:
        ///     sql:传入要执行sql语句
        ///     orderField:排序字段
        ///     orderType:排序类型
        ///     pageIndex:当前页
        ///     pageSize:页大小
        ///     count:返回查询条数
        /// </summary>
        public DataTable GetPageList(string sql, string orderField, string orderType, int pageIndex, int pageSize, ref int count)
        {
            return GetPageList(sql, null, orderField, orderType, pageIndex, pageSize, ref  count);
        }
        #endregion