手写分页sql_ADO SQL手写分页

//实现层

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

public List 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>(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; };

{

}

}

@{

var next = ViewBag.pageindex;

next++;

if (next > ViewBag.fy) { next = ViewBag.fy; };

{

}

}

SQL语句

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

--高老师传授的分页,毕生受用!!

select top(2) *from (select ROW_NUMBER() over (order by Id)iid,*from Exam02)fy where iid>((1-1)*2)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值