zoukankan      html  css  js  c++  java
  • 分页的拼接字符串的方法

     /// <param name="tableName">table名称</param>
            /// <param name="keyFieldName">主键字段名称</param>
            /// <param name="currentPageIndex">当前页码</param>
            /// <param name="pageCount">每页显示记录数</param>
            /// <param name="conditionString">限制条件字符串</param>
            /// <returns></returns>
            protected virtual string GetExecutePageingSql(string tableName, string keyFieldName, int currentPageIndex, int pageCount, string conditionString)
            {
                if (string.IsNullOrEmpty(tableName))
                {
                    throw new ArgumentNullException("tableName");
                }

                if (string.IsNullOrEmpty(keyFieldName))
                {
                    throw new ArgumentNullException("keyFieldName");
                }

                if (currentPageIndex < 0)
                {
                    throw new ApplicationException(string.Format(@"currentPageIndex值为:{0},currentPageIndex必须大于等于1,该值不符合要求。", currentPageIndex));
                }

                if (pageCount < 1)
                {
                    throw new ApplicationException(string.Format(@"pageCount值为:{0},pageCount必须大于等于1,该值不符合要求。", pageCount));
                }

                StringBuilder stringBuilder = new StringBuilder();

                stringBuilder.AppendFormat(@"select top {0} * from {1} where {2} not in(select top {3} {2} from {1}  where 1=1 {4}) {4};select count(*) from {1} where 1=1 {4};",
                    pageCounts,
                    tableName,
                    keyFieldName,
                    pageCount * (currentPageIndex - 1),
                    conditionString);

                return Convert.ToString(stringBuilder);
            }

    1=1可以理解成and

  • 相关阅读:
    查看uCOS-II的CPU使用率
    ARM的工作环境和工作模式
    一个简单的 JSON 生成/解析库
    [转] libtool的作用及应用
    Qt 使用 net-snmp 包的过程记录
    Qt 立体水晶按键实现
    xampp 修改 mysql 默认 root 密码
    mint 设置无线 AP
    dpkg 小记
    转-ubuntu清理卸载wine的残余项目
  • 原文地址:https://www.cnblogs.com/meroselove/p/2205413.html
Copyright © 2011-2022 走看看