欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ADO SQL手写分页

程序员文章站 2022-08-10 11:39:56
//实现层 分割线 public List ShowListPage(int pageindex, int pagesize) { string sql = string.Format("select top({0}) *from (select ROW_NUMBER() ov ......

 

//实现层

---------------------------------------------------------分割线---------------------------------------------------------

public list<usermodel> showlistpage(int pageindex, int pagesize)
{
string sql = string.format("select top({0}) *from (select row_number() over (order by id)iid,*from usertype)fy where iid>(({1}-1)*{2})", pagesize, pageindex, pagesize);
datatable dt = dbhelper.gettable(sql);
var str = jsonconvert.serializeobject(dt);
return jsonconvert.deserializeobject<list<usermodel>>(str);
}

//控制器

---------------------------------------------------------分割线---------------------------------------------------------

public actionresult showpage(int pageindex=1)
{
//一页显示2条数据
int pagesize = 2;
//记录总的条数
int pagecount = idal.showcount();

//当条数为总数时
if (pagecount % pagecount == 0)
{
viewbag.fy = pagecount / pagesize;
}
else
{
viewbag.fy = (pagecount / pagesize) + 1;
}
//页数
viewbag.pageindex = pageindex;
viewbag.pagesize = pagesize;
viewbag.pagecount = pagecount;
viewbag.list = idal.showlistpage(pageindex, pagesize);
var resulr = idal.showcount();
return view(resulr);
}

//ui前台显示

---------------------------------------------------------分割线---------------------------------------------------------

@{
var shang = viewbag.pageindex;
shang--;
if (shang < 0) { shang = 1; };
{
<input id="button1" type="button" value="首页" onclick="location.href='/user/showpage?pageindex=1'" />
<input id="button1" type="button" value="上一页" onclick="location.href='/user/showpage?pageindex=@shang'" />
}
}

@{
var next = viewbag.pageindex;
next++;
if (next > viewbag.fy) { next = viewbag.fy; };
{
<input id="button1" type="button" value="下一页" onclick="location.href='/user/showpage?pageindex=@next'" />
<input id="button1" type="button" value="尾页" onclick="location.href='/user/showpage?pageindex=@viewbag.fy'" />
}
}

sql语句

---------------------------------------------------------分割线---------------------------------------------------------

--高老师传授的分页,毕生受用!!
select top(2) *from (select row_number() over (order by id)iid,*from exam02)fy where iid>((1-1)*2)