|
利用c#制作简单的留言板(1) (3) catch(Exception e) { throw(new Exception("取贴子失败:" + e.ToString())) ; } return true;
}
/// <summary> /// 取的贴子列表 /// </summary> /// <remarks> /// 返回一个Topic数组 /// </remarks> public ArrayList GetTopicList() { //定义一个forum数组做为返回值 ArrayList arrForumList =new ArrayList() ;
//从数据库中读取留言列表 myconn myConn = new myconn(); SQLCommand myCommand = new SQLCommand() ; myCommand.ActiveConnection = myConn ; myCommand.CommandText = "n_GetTopicList" ; //调用存储过程 myCommand.CommandType = CommandType.StoredProcedure ;
try { myConn.Open() ; SQLDataReader myReader ; myCommand.Execute(out myReader) ;
for (int i = 0 ; myReader.Read() ; i++) { notepage objItem = new notepage() ; objItem.ID = myReader["ID"].ToString().ToInt32() ; objItem.Title = myReader["Title"].ToString() ; objItem.Author = myReader["Author"].ToString() ; objItem.adddate = myReader["adddate"].ToString().ToDateTime(); objItem.Content = myReader["Content"].ToString();
arrForumList.Add(objItem) ; }
//清场 myReader.Close(); myConn.Close() ;
} catch(SQLException e) { throw(new Exception("数据库出错:" + e.ToString())) ; //return null ; }
return arrForumList ; }
} }
|