一、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();
效果图: