//定义一个连接对象
SqlConnection conn = new SqlConnection(strconn);
int PageIndex = 1;
int PageSize = 10;
int PageCount;
string ViewName="Record";
string Field = "*";
//定义一个SqlCommand 对象
SqlCommand comm = new SqlCommand("Pagination",conn);
//定义SqlCommand 对象的执行命令为存储过程
comm.CommandType = CommandType.StoredProcedure;
//添加一个参数,并指出其类型
comm.Parameters.Add("@PageIndex",SqlDbType.Int);
//给参数@PageIndex赋值
comm.Parameters["@PageIndex"].Value=PageIndex;
comm.Parameters.Add("@PageSize",SqlDbType.Int);
comm.Parameters["@PageSize"].Value=PageSize;
comm.Parameters.Add("@RecordCount",SqlDbType.Int);
//如果是输出参数,显式指出
comm.Parameters["@RecordCount"].Direction=ParameterDirection.Output;
comm.Parameters.Add("@PageCount", SqlDbType.Int);
comm.Parameters["@PageCount"].Direction = ParameterDirection.Output;
comm.Parameters.Add("@ViewName", SqlDbType.VarChar, 50);
comm.Parameters["@ViewName"].Value = ViewName;
comm.Parameters.Add("@Field", SqlDbType.VarChar, 200);
comm.Parameters["@Field"].Value = Field;
conn.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comm;
comm.ExecuteNonQuery();
DataSet ds = new DataSet();
da.Fill(ds);
//取得输出参数,注意用流读取时,不能成功取出参数
PageCount = System.Convert.ToInt32(comm.Parameters["@PageCount"].Value);
string strPageCount = comm.Parameters["@PageCount"].Value.ToString();