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


     /// <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
  • 相关阅读:
    bzoj1467 Pku3243 clever Y
    bzoj2242 [SDOI2011]计算器
    卡特兰数
    洛谷P1290 欧几里得的游戏
    bzoj2277 [Poi2011]Strongbox
    poj2406 Power Strings
    Codeforces 892 D.Gluttony
    Codeforces 892 C.Pride
    Codeforces 892 B.Wrath
    Codeforces 892 A.Greed
  • 原文地址:https://www.cnblogs.com/zoumin123/p/6387425.html
Copyright © 2020-2023  润新知