下面这个Demo用的是MVC+Ado.Net、存储过程
实现功能:分页查询,添加、修改功能。模糊查询功能
先来几张效果图:
创建存储过程如下
go create proc usp_FenYe2 @selId int, @selName nvarchar, @pageIndex int, @pageSize int, @recordCount int output, @pageCount int output as begin if @selId!=0 and (@selName=‘‘) begin select *from( select *,rn=ROW_NUMBER() over(order by UserId) from UserMsg where IsDelete=1 and( UserId=@selId) )as t where t.rn between ((@pageIndex-1)*@pageSize+1) and @pageIndex*@pageSize set @recordCount=(select count(*) from (select *from UserMsg where IsDelete=1 and( [email protected]))as t); set @pageCount=CEILING((@recordCount*1.0)/@pageSize) end else if @selId=0 and (@selName!=‘‘) begin select *from( select *,rn=ROW_NUMBER() over(order by UserId) from UserMsg where IsDelete=1 and( UserName like ‘%‘[email protected]+‘%‘) )as t where t.rn between ((@pageIndex-1)*@pageSize+1) and @pageIndex*@pageSize set @recordCount=(select count(*) from (select * from UserMsg where IsDelete=1 and( UserName like ‘%‘[email protected]+‘%‘))as t); set @pageCount=CEILING((@recordCount*1.0)/@pageSize) end else if @selId!=0 and(@selName!=‘‘) begin select *from( select *,rn=ROW_NUMBER() over(order by UserId) from UserMsg where IsDelete=1 and([email protected] or(UserName like ‘%‘[email protected]+‘%‘)) )as t where t.rn between ((@pageIndex-1)*@pageSize+1) and @pageIndex*@pageSize set @recordCount=(select count(*) from (select *from UserMsg where IsDelete=1 and([email protected] or (UserName like ‘%‘[email protected]+‘%‘)))as t); set @pageCount=CEILING((@recordCount*1.0)/@pageSize) end else begin select *from( select *,rn=ROW_NUMBER() over(order by UserId) from UserMsg where IsDelete=1)as t where t.rn between ((@pageIndex-1)*@pageSize+1) and @pageIndex*@pageSize set @recordCount=(select count(*) from UserMsg); set @pageCount=CEILING((@recordCount*1.0)/@pageSize) end end go
整个项目代码见:https://github.com/shuai7boy/easyUITest
时间: 2024-10-24 16:06:38