剑挥清风指明月·笔走狂澜舞镹天

三尺长剑,斩不断相思情缠!

封装一个生成分页SQL

 /// <summary>
        /// 查询分页
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <param name="pageCount">每页显示条</param>
        /// <param name="pageNumber">页数</param>
        /// <param name="orderBy">排序字段order by xxx  asc</param>
        /// <returns></returns>
        public string GetPageSQL(string sql, int pageCount, int pageNumber, string 
        orderBy)
        {
            sql = string.Format(@"SELECT  top {2}* FROM(SELECT ROW_NUMBER() OVER ({3}) 
            AS RowNumber,* FROM ({0}) m ) 
            t  WHERE RowNumber > {1} ", sql, (pageNumber - 1) * pageCount, pageCount, 
            orderBy);
            return sql;
        }

调用示例

string sql = @"select  * from lcsy_PlanLog";

string pagesql = GetPageSQL(sql, 5, 0, "order by cid  desc");
阅读更多
版权声明:本文为博主原创文章,未经博主允许请随意转载,注明出处! https://blog.csdn.net/u010085423/article/details/53991409
文章标签: sql 分页
个人分类: C# SQLServer
上一篇简单工厂模式
下一篇Mvc 中Controller返回类型
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭