Sql Server 编写分页存储过程

来源:互联网 发布:php开源博客系统 编辑:程序博客网 时间:2024/05/21 17:44

一、Sql 存储过程中的编写及执行

--创建存储过程create proc BookInfo@pageSize int,@pageIndex intas select top(@pageSize) *from dbo.Books where BNO not in(select top(@pageSize*(@pageIndex-1)) BNOfrom 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();

效果图:


0 0
原创粉丝点击