zoukankan      html  css  js  c++  java
  • 通过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
  • 相关阅读:
    51Nod 1006 最长公共子序列Lcs
    输入和输出
    51Nod 1092 回文字符串
    51Nod 1050 循环数组最大子段和
    项目初始
    一元多项式求导 (25)
    说反话 (20)
    数组元素循环右移问题 (20)
    素数对猜想 (20)
    换个格式输出整数 (15)
  • 原文地址:https://www.cnblogs.com/zoumin123/p/6387425.html
Copyright © 2011-2022 走看看