首页 > 数据库技术 > 详细

通过sql 实现简单分页(not in)

时间:2017-02-10 19:51:38      阅读:270      评论:0      收藏:0      [点我收藏+]
技术分享
 /// <summary>
    /// 分页查询的sql语句
    /// </summary>
    /// <param name="attributes">要查询的字段(两端可以没有空格)</param>
    /// <param name="pageSize">每页要显示的行数</param>
    /// <param name="pageIndex">当前页索引</param>
    /// <param name="orderBy">依据那个字段排序(两端可以没有空格)</param>
    /// <param name="aod">升序(asc)还是降序(desc)(两端可以没有空格)</param>
    /// <param name="where">附加的条件(一定要有where关键字,两端可以没有空格)</param>
    /// <returns></returns>
    public static string SelectByPaging(int currentPageIndex, string field, int pageSize, string strWhere, string orderByWho, string orderDirection)
    {
        string ids = string.Format("SELECT TOP({0}*{1}) id FROM Base_Knowledge {2} ORDER BY {3} {4}", currentPageIndex, pageSize, strWhere, orderByWho, orderDirection);
        string whereLess = null;
        if (!string.IsNullOrEmpty(strWhere))
        {
            int whereIndex = strWhere.ToLower().IndexOf("where");
            whereLess = "AND" + strWhere.Substring(whereIndex + 5);
        }
        return string.Format(@"SELECT TOP {0} {1} FROM Base_Knowledge WHERE id NOT IN({2}) {3} ORDER BY {4} {5}",
        pageSize, field, ids, whereLess, orderByWho, orderDirection);
    }
View Code

 

 

通过sql 实现简单分页(not in)

原文:http://www.cnblogs.com/zoumin123/p/6387425.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!