给你一个我写好的吧,你看看。。。有疑问的话留言探讨。。。共同进步
带参还包括了输出参数
存储过程
ALTER PROCEDURE [dbo].[GetLinkPageOutRowPageCount]
(
@PageIndex int =1,--当前页数
@PageSize int =4,--当前页大小
@RowCount int output,--总行数(传出参数)
@PageCount int output--总页数(传出参数)
)
AS
begin
DECLARE @sql NVARCHAR(max),@sqlCount NVARCHAR(225)
select @RowCount =COUNT(FId),@PageCount=CEILING((COUNT(FId)+0.0)/@PageSize) FROM TLinks
SET @sql='SELECT TOP '+LTRIM(str(@PageSize))+' * FROM TLinks where FId not in(select top '+LTRIM(str((@PageIndex-1)*@PageSize))+' FId from TLinks order by FSortId DESC , FAddTime ASC)order by FSortId DESC , FAddTime ASC'
print @sql
EXEC(@sql)
end
c#中调用赋值和接收输出参数的值
#region 友情链接执行简单先根据自定义int字段排序再时间进行排序查询分页存储过程
/// <summary>
/// 友情链接执行简单先根据自定义int字段排序再时间进行排序查询分页存储过程
/// </summary>
/// <param name="pageIndex">页码</param>
/// <param name="pageSize">页容量</param>
/// <param name="rowCount">总行数-输出</param>
/// <param name="pageCount">总页数-输出</param>
/// <returns></returns>
public DataTable ExecProSimplePageList(int pageIndex, int pageSize, out int rowCount, out int pageCount)
{
rowCount = 1;
pageCount = 1;
SqlParameter[] parameters = {
new SqlParameter("@PageIndex", SqlDbType.Int,4),
new SqlParameter("@PageSize", SqlDbType.Int,4),
new SqlParameter("@RowCount", SqlDbType.Int,4),
new SqlParameter("@PageCount", SqlDbType.Int,4)};
parameters[0].Value = pageIndex;
parameters[1].Value = pageSize;
parameters[2].Value = rowCount;
parameters[2].Direction = ParameterDirection.Output;
parameters[3].Value = pageCount;
parameters[3].Direction = ParameterDirection.Output;
SqlCommand cmd = new SqlCommand();
cmd.Connection = Conn;
cmd.CommandText = "GetLinkPageOutRowPageCount";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddRange(parameters);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
rowCount = Convert.ToInt32(parameters[2].Value);
pageCount = Convert.ToInt32(parameters[3].Value);
return dt;
}
#endregion |