Exemplo n.º 1
0
        /// <summary>
        /// 摘要:
        ///     数据分页接口
        /// 参数:
        ///     sql:传入要执行sql语句
        ///     param:参数化
        ///     orderField:排序字段
        ///     orderType:排序类型
        ///     pageIndex:当前页
        ///     pageSize:页大小
        ///     count:返回查询条数
        /// </summary>
        public static DataTable GetPageList(string sql, SqlParameter[] 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 = SQLServerHelper.ExecuteDt("Select Count(1) From (" + sql + ") As t", param).Rows.Count;
                return(SQLServerHelper.ExecuteDt(sb.ToString(), param));
            }
            catch (Exception e)
            {
                ////Logger.WriteLog("-----------数据分页(Oracle)-----------\r\n" + sb.ToString(), e);
                return(null);;
            }
        }