首页 > 数据库技术 > 详细

ADO SQL手写分页

时间:2019-02-27 21:09:10      阅读:202      评论:0      收藏:0      [点我收藏+]

 

//实现层

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

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)

ADO SQL手写分页

原文:https://www.cnblogs.com/MNCnblogs/p/10446847.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!