/// <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