public IList<Punishment> GetPunishmentPaging(int pageSize, int pageIndex, string Fields, string orderStr, int sortDescending, string where, out int recordCount)
{
recordCount = 0;
DbCommand command = DB.GetStoredProcCommand("sp_Pagination2005");
DB.AddInParameter(command, "@tblName", SqlDbType.NVarChar, "db_consult_punishment");
DB.AddInParameter(command, "@fields", SqlDbType.NVarChar, Fields);
DB.AddInParameter(command, "@sortField", SqlDbType.NVarChar, orderStr);
DB.AddInParameter(command, "@pageSize", SqlDbType.Int, pageSize);
DB.AddInParameter(command, "@pageIndex", SqlDbType.Int, pageIndex);
DB.AddInParameter(command, "@sortDescending", SqlDbType.Bit, sortDescending); DB.AddOutParameter(command, "@totalRecords", SqlDbType.Int, 4);
DB.AddInParameter(command, "@strWhere", SqlDbType.NVarChar, where); IList < Punishment > list= null;
using (var reader = DB.ExecuteReader(command))
{
list = reader.ReaderToList<Punishment>();
}
recordCount = (int)DB.GetParameterValue(command, "@totalRecords");
return list;
}但换成这样 public IList<Punishment> GetPunishmentPaging(int pageSize, int pageIndex, string Fields, string orderStr, int sortDescending, string where, out int recordCount)
{
recordCount = 0;
DbCommand command = DB.GetStoredProcCommand("sp_Pagination2005");
DB.AddInParameter(command, "@tblName", SqlDbType.NVarChar, "db_consult_punishment");
DB.AddInParameter(command, "@fields", SqlDbType.NVarChar, Fields);
DB.AddInParameter(command, "@sortField", SqlDbType.NVarChar, orderStr);
DB.AddInParameter(command, "@pageSize", SqlDbType.Int, pageSize);
DB.AddInParameter(command, "@pageIndex", SqlDbType.Int, pageIndex);
DB.AddInParameter(command, "@sortDescending", SqlDbType.Bit, sortDescending); DB.AddOutParameter(command, "@totalRecords", SqlDbType.Int, 4);
DB.AddInParameter(command, "@strWhere", SqlDbType.NVarChar, where); using (var reader = DB.ExecuteReader(command))
{
recordCount = (int)DB.GetParameterValue(command, "@totalRecords");
return reader.ReaderToList<Punishment>();
}
}会在recordCount = (int)DB.GetParameterValue(command, "@totalRecords");产生null不能转为int类型
为什么这么不能取到@totalRecords的值,而第一种却可以呢?
数据库是可以取到的。我用的是企业库
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货