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 ;
}