Datalist控件使用存储过程来分页实现代码(2)


CREATE PROCEDURE [dbo].[sp_Product_Select_by_Page_rowNumber]
@pageSize int, --每页记录数量
@pageCount int output, --总页数
@pageIndex int --当前页索引号
AS
BEGIN
declare @totalRecords int
select @totalRecords = count(PId) from Product
if(@totalRecords % @pageSize = 0)
set @pageCount = @totalRecords / @pageSize;
else
set @pageCount = @totalRecords / @pageSize +1;
with temp as (select row_number() over (order by PId) as id,* from Product)
select * from temp where id between (@pageIndex -1)*@pageSize +1 and @pageIndex * @pageSize
return @totalRecords
end
GO


----------------Web.config:-------------------

复制代码 代码如下:


<connectionStrings>
<add connectionString="Data Source=PC_THINK-THINK;Initial Catalog=student;Persist Security Info=True;User ID=sa;Password=111111"
providerName="System.Data.SqlClient" />
</connectionStrings>


----------------------SQLHelper类:-------------------------------------

复制代码 代码如下:


public static String connStr = ConfigurationManager.ConnectionStrings["studentConnectionString"].ConnectionString;
public static int ExecuteNonQuery(string sql, params SqlParameter[] pms)
{
using (SqlConnection con = new SqlConnection(connStr))
{
using (SqlCommand cmd = new SqlCommand(sql, con))
{
if (pms != null)
{
cmd.Parameters.AddRange(pms);
}
con.Open();
return cmd.ExecuteNonQuery();
}
}
}
public static DataTable ExecuteDataTable(string sql, params SqlParameter[] pms)
{
DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(sql,connStr);
if (pms != null)
{
adapter.SelectCommand.Parameters.AddRange(pms);
}
adapter.Fill(dt);
return dt;
}

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjdxzw.html