日期:2014-05-17  浏览次数:20430 次

为什么没有执行while里面的代码 直接执行return list呢,三个参数的值都获取到了 谁帮解决下 谢谢啊 在线求解~
/// <summary>
  /// 产品分页展示根据ClassName
  /// </summary>
  /// <param name="pagesize">每页显示多少条</param>
  /// <param name="pageindex">当前第几页</param>
  /// <returns>返回List<prod_news>集合</returns>
  public List<prod_news> ProductFenYeByClassName(int pagesize, int pageindex,string className)
  {
  try
  {
  int num = pagesize * pageindex;
  string sqlStr = "select top 12 * from prod_news where ID not in (select top " + num + " ID from prod_news order by infotime desc) and ClassName="+className+" order by infotime desc";
  OleDbCommand cmd = new OleDbCommand(sqlStr, con);
  OleDbParameter par1 = new OleDbParameter("@pagesize", OleDbType.Integer);
  OleDbParameter par2 = new OleDbParameter("@pageindex", OleDbType.Integer);
  OleDbParameter par3=new OleDbParameter("@ClassName",OleDbType.VarChar);
  par1.Value = pagesize;
  par2.Value = pageindex;
  par3.Value=className;
  cmd.Parameters.Add(par1);
  cmd.Parameters.Add(par2);
  cmd.Parameters.Add(par3);
  List<prod_news> list = new List<prod_news>();
  con.Open();
  OleDbDataReader reader = cmd.ExecuteReader();
  while (reader.Read())
  {
  prod_news prod_news = new prod_news();
  prod_news.ID = Convert.ToInt32(reader["ID"]);
  prod_news.title = reader["title"].ToString();
  prod_news.content = reader["content"].ToString();
  prod_news.ClassName = reader["ClassName"].ToString();
  prod_news.img = reader["img"].ToString();
  prod_news.okay2 = Convert.ToInt32(reader["okay2"]);
  prod_news.okay = Convert.ToInt32(reader["okay"]);
  prod_news.infotime = Convert.ToDateTime(reader["infotime"]);
  prod_news.hits = Convert.ToInt32(reader["hits"]);
  prod_news.ok = Convert.ToBoolean(reader["ok"]);
  list.Add(prod_news);
  }
  return list;
  }
  catch (Exception ec)
  {
  throw ec;
  }
  finally
  {
  con.Close();
  }
  }


为什么没有执行while里面的代码 直接执行return list呢,三个参数的值都获取到了 谁帮解决下 谢谢啊 在线求解~

------解决方案--------------------
应该是没有查询出来数据,你断点进去看下SQL是怎样的,然后在ACCESS里面执行看看