两种asp.net 分页
select * from
(
select top 10 * from News where NewsId not in(select top 30 NewsId from News
)
)e
select * from (
select *,row_number() over(order by badge) rn
from 表) a
where rn between @pagesize*(@pageNum-1) and @pagesize*(@pageNum)-1
public DataSet GetList(int PageSize, int PageIndex, string strWhere)
{
//select top 2 * from NewsType where TypeId not in (select top 2 TypeId from NewsType)
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from(");
strSql.Append("select * ,ROW_NUMBER() over(order by NewsId) nid from News)a where nid between @pagesize*(@pageNum-1) and @pagesize*(@pageNum)-1");
if (strWhere.Trim() != "")
{
strSql.Append(" where @strWhere");
}
SqlParameter[] parameters = {
new SqlParameter("@pagesize", SqlDbType.Int,4),
new SqlParameter("@pageNum", SqlDbType.Int,4),
new SqlParameter("@strWhere", SqlDbType.VarChar,255)
};
parameters[0].Value = PageSize;
parameters[1].Value = PageIndex;
parameters[2].Value = strWhere;
DataSet ds = SqlHelper.ExecuteDataset(_connectionString, CommandType.Text, strSql.ToString(),parameters);
return ds;
}
{
//select top 2 * from NewsType where TypeId not in (select top 2 TypeId from NewsType)
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from(");
strSql.Append("select * ,ROW_NUMBER() over(order by NewsId) nid from News)a where nid between @pagesize*(@pageNum-1) and @pagesize*(@pageNum)-1");
if (strWhere.Trim() != "")
{
strSql.Append(" where @strWhere");
}
SqlParameter[] parameters = {
new SqlParameter("@pagesize", SqlDbType.Int,4),
new SqlParameter("@pageNum", SqlDbType.Int,4),
new SqlParameter("@strWhere", SqlDbType.VarChar,255)
};
parameters[0].Value = PageSize;
parameters[1].Value = PageIndex;
parameters[2].Value = strWhere;
DataSet ds = SqlHelper.ExecuteDataset(_connectionString, CommandType.Text, strSql.ToString(),parameters);
return ds;
}
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public void bingdlist()
{
int indexpage = Convert.ToInt32(Request["page"]);
if (indexpage == 0)
{
indexpage = 1;
}
Response.Write(indexpage);
News newsinfo = new News();
DataSet ds = newsinfo.GetList(pagesize, indexpage, "");
newsrep.DataSource = ds;
newsrep.DataBind();
}
{
int indexpage = Convert.ToInt32(Request["page"]);
if (indexpage == 0)
{
indexpage = 1;
}
Response.Write(indexpage);
News newsinfo = new News();
DataSet ds = newsinfo.GetList(pagesize, indexpage, "");
newsrep.DataSource = ds;
newsrep.DataBind();
}