您的位置:首页 > 数据库

Sql Server 编写分页存储过程

2016-03-26 21:34 555 查看
一、Sql 存储过程中的编写及执行

--创建存储过程
create proc BookInfo
@pageSize int,
@pageIndex int
as
select top(@pageSize) *
from dbo.Books
where BNO not in(
select top(@pageSize*(@pageIndex-1)) BNO
from dbo.Books
)--这里只使用了单表查询,最常使用的是多表链接查询

--使用情况
exec BookInfo 5,5


二、程序中调用存储过程

string sqlConnection = "Data Source=.;Initial Catalog=LibrarySyatem;Integrated Security=True";
SqlConnection connection = new SqlConnection(sqlConnection);
SqlCommand command = new SqlCommand("BookInfo", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@pageIndex", 5));
command.Parameters.Add(new SqlParameter("@pageSize", 5));
SqlDataAdapter ad = new SqlDataAdapter(command);
DataSet ds = new DataSet();
ad.Fill(ds);
this.GridView1.DataSource = ds;
this.GridView1.DataBind();


效果图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: