存储过程分页,出错!为什么?
wtle 2013-09-21 07:01:25
C#:
private void bind(int PageIndex)
{
string sql = "flag='0'";
int PageSize = Convert.ToInt16(DBConfig.PageSize);
DataSet ds = new DataSet();
DB.OpenConnection();
SqlCommand cmd = new SqlCommand("sp_All_Pager2", DBConfig.cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlCommandBuilder.DeriveParameters(cmd);
cmd.Parameters["@tblName"].Value = "HR";
cmd.Parameters["@fldNames"].Value = "id,name";
cmd.Parameters["@fldNames2"].Value = "(SELECT pid FROM HR2 WHERE (HRid = tmpTable.id)) AS pid";
cmd.Parameters["@fldOrderName"].Value = "id";
cmd.Parameters["@orderType"].Value = 0;
cmd.Parameters["@PageIndex"].Value = PageIndex;
cmd.Parameters["@PageSize"].Value = PageSize;
cmd.Parameters["@strWhere"].Value = sql;
cmd.Parameters["@totalCount"].Direction = ParameterDirection.Output;
SqlDataAdapter dp = new SqlDataAdapter();
dp.SelectCommand = cmd;
dp.Fill(ds, "hrdocmi");
int PageCount;
int RecordCount = Convert.ToInt32(cmd.Parameters["@totalCount"].Value);
if (RecordCount == 0)
{
PageCount = 1;
}
else
{
if (RecordCount % PageSize == 0)
PageCount = RecordCount / PageSize;
else
PageCount = RecordCount / PageSize + 1;
}
this.PageNavigator1.PageCount = PageCount;
this.PageNavigator1.PageIndex = PageIndex;
this.PageNavigator1.RecordCount = RecordCount;
Repeater1.DataSource = ds.Tables[0];
Repeater1.DataBind();
ds.Clear();
dp.Dispose();
DB.CloseConnection();
}