日期:2014-05-18 浏览次数:20808 次
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER procedure [dbo].[SqlPage] @TableName varchar(50), --表或视图名 @Fields varchar(5000) = '*', --字段名(全部字段为*) @OrderFields varchar(5000), --排序字段(必须!支持多字段,建议建索引) @SqlWhere varchar(5000) = '', --条件语句(如and Name='a') @PageSize int, --每页多少条记录 @PageIndex int = 1 , --指定当前为第几页 @TotalPages int output --返回总页数 as begin declare @sql nvarchar(4000) declare @TotalRecords int --+ 50, p.Y));
private void Page(String Id) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString)) { using (SqlDataAdapter Da = new SqlDataAdapter("SqlPage", conn)) { Da.SelectCommand.Parameters.Add(new SqlParameter("@TableName","Article")); Da.SelectCommand.Parameters.Add(new SqlParameter("@Fields","Id,Title,AddTime")); Da.SelectCommand.Parameters.Add(new SqlParameter("@OrderFields"," order by id desc")); Da.SelectCommand.Parameters.Add(new SqlParameter("@SqlWhere","")); Da.SelectCommand.Parameters.Add(new SqlParameter("@PageSize",30)); Da.SelectCommand.Parameters.Add(new SqlParameter("@PageIndex",1)); SqlParameter Para=new SqlParameter("@TotalPages",SqlDbType.Int); Para.Direction = ParameterDirection.Output; Da.SelectCommand.Parameters.Add(Para); DataSet Dt = new DataSet(); Da.Fill(Dt); GridView1.DataSource = Dt; GridView1.DataBind(); conn.Close(); } } }