日期:2014-05-18  浏览次数:20690 次

当ArrayList碰到object的时候,出问题了
con.Open();
  OleDbCommand cmd = new OleDbCommand("select * from table1", con);
  OleDbDataReader oldr = cmd.ExecuteReader();

  object_class newobj = new object_class();
  while (oldr.Read())
  {
  newobj.str = oldr["url"].ToString();
  newobj.Name = oldr["name"].ToString();
  alMsgList.Add(newobj); 
  }
  for (int i = 0; i < alMsgList.Count; i++)
  {
  object_class obj = (object_class)alMsgList[alMsgList.Count - i - 1];
  richTextBox1.AppendText(obj.Name.ToString());
  Delay(1000);
  }
  con.close()
为何richTextBox1出现的一直是最后一条数据?求解释

------解决方案--------------------
newobj放在while里试试
while (oldr.Read())
{
object_class newobj = new object_class();
newobj.str = oldr["url"].ToString();
newobj.Name = oldr["name"].ToString();
alMsgList.Add(newobj);
}