我不抽烟

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;


namespace pager
{
public class Pager
{
/// <summary>
///
/// </summary>
/// <param name="strWhere">条件</param>
/// <param name="pagesize">每页显示条数</param>
/// <param name="pageindex">第几页</param>
/// <param name="orderCol">排序</param>
/// <param name="TableName">表名</param>
/// <returns></returns>
public static string GetPager(string strWhere, int pagesize, int pageindex, string orderCol, string TableName)
{
if (pageindex == 1)
{
return "select top " + pagesize.ToString() + " * from " + TableName.ToString() + " order by " + orderCol.ToString() + " DESC";
}
else
{
StringBuilder strSql = new StringBuilder();
strSql.AppendFormat("select top {0} * from {1} ", pagesize, TableName);
strSql.AppendFormat(" where {1} not in (select top {0} id from {2} ", pagesize * (pageindex - 1), orderCol, TableName);
if (strWhere.Trim() != "")
{
strSql.AppendFormat(" where {0} order by {1} DESC) and {0}", strWhere, orderCol);
}
else
{
strSql.AppendFormat(" order by {0} DESC) ", orderCol);
}
strSql.AppendFormat(" order by {0} DESC", orderCol);

return strSql.ToString();
}
}
}
}

希望对大家有用~~~

posted on 2012-07-05 19:33  小李弯刀  阅读(335)  评论(2编辑  收藏  举报