ArrayList應用
2024-07-21 02:20:22
供稿:網友
注冊會員,創建你的web開發資料庫, /// <summary>
/// 取的貼子列表
/// </summary>
/// <remarks>
/// 返回一個forum數組
/// </remarks>
public arraylist getforumlist()
{
//定義一個forum數組做為返回值
arraylist arrforumlist =new arraylist() ;
//從數據庫中讀取版面列表
myclass.util.myconnection myconn = new myclass.util.myconnection("bbs") ;
sqlcommand mycommand = new sqlcommand() ;
mycommand.activeconnection = myconn ;
mycommand.commandtext = "up_getforumlist" ; //調用存儲過程
mycommand.commandtype = commandtype.storedprocedure ;
try
{
myconn.open() ;
sqldatareader myreader ;
mycommand.execute(out myreader) ;
for (int i = 0 ; myreader.read() ; i++)
{
myclass.bbs.forum objitem = new myclass.bbs.forum() ;
objitem.id = myreader["id"].tostring().toint32() ;
objitem.name = myreader["title"].tostring() ;
objitem.description = myreader["description"].tostring() ;
objitem.topiccount = myreader["topiccount"].tostring().toint32() ;
objitem.layer = myreader["layer"].tostring().toint32() ;
objitem.fatherid = myreader["fatherid"].tostring().toint32() ;
objitem.master = new bbsuser(myreader["userid"].tostring().toint32() ,
myreader["username"].tostring() , myreader["email"].tostring() ,
myreader["homepage"].tostring() , myreader["signature"].tostring()) ;
arrforumlist.add(objitem) ;
}
//清場
myreader.close();
myconn.close() ;
}
catch(sqlexception e)
{
throw(new exception("數據庫出錯:" + e.tostring())) ;
//return null ;
}
return arrforumlist ;
}