国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

利用c#制作簡單的留言板(1)

2024-07-21 02:17:47
字體:
來源:轉載
供稿:網友
,歡迎訪問網頁設計愛好者web開發。 

留言板分三個模塊:列出留言列表、顯示詳細內容、發表留言
notepage.cs
namespace notpage
{
using system;
using system.data.sql ;
using system.data ;
using system.collections ;

/// <summary>
/// summary description for notepage.
/// </summary>


public class notepage
{
//私有變量

private int n_intid ; //id編號
private string n_strtitle ; //主題
private string n_strauthor ; //留言人
private string n_strcontent ; //留言內容
private datetime n_datetime ; //留言時間


//屬性


public int id
{
get
{
return n_intid ;
}
set 
{
n_intid = value;
}
}

public string title 
{
get
{
return n_strtitle ;
}
set
{
n_strtitle = value;
}
}

public string author
{
get
{
return n_strauthor ;
}
set
{
n_strauthor = value ;
}
}
public string content
{
get
{
return n_strcontent ;
}
set
{
n_strcontent = value ;
}
}
public datetime adddate
{

get
{
return n_datetime;
}
set
{
n_datetime = value;
}
}
//構造函數
public notepage()
{
//
// todo: add constructor logic here
//
this.n_intid = 0 ;
this.n_strtitle = "" ;
this.n_strauthor = "" ;
this.n_strcontent = "" ;
this.n_datetime = system.datetime.now;

}

/// <summary>
/// 
/// 取得留言的內容
/// 
/// </summary>
/// <param name="a_intid"> </param>
public notepage gettopic(int a_intid)
{
//
// todo: add constructor logic here
//



//讀取數據庫
myconn myconn = new myconn();

sqlcommand mycommand = new sqlcommand() ;
mycommand.activeconnection = myconn ;
mycommand.commandtext = "n_gettopicinfo" ; //調用存儲過程
mycommand.commandtype = commandtype.storedprocedure ;
mycommand.parameters.add(new sqlparameter("@a_inttopicid" , sqldatatype.int)) ;
mycommand.parameters["@a_inttopicid"].value = a_intid ;

notepage objnp = new notepage();
try


myconn.open() ;
sqldatareader myreader ;
mycommand.execute(out myreader) ;
if (myreader.read())
{
objnp.id = (int)myreader["id"] ;
objnp.title = (string)myreader["title"] ;
objnp.author = (string)myreader["author"] ;
objnp.content = (string)myreader["content"];
objnp.adddate = (datetime)myreader["adddate"];
}



//清場
myreader.close();
myconn.close() ;

}
catch(exception e)
{
throw(new exception("取貼子失敗:" + e.tostring())) ;
}
return objnp;

}

/// <summary>
/// 
/// 目的:將留言的內容入庫
/// 
/// 利用構造函數來傳遞信息
/// 
/// </summary>
/// <param name="n_topic"> </param>
public bool addtopic(notepage n_topic)
{
//
// todo: add constructor logic here
//

//讀取數據庫
myconn myconn = new myconn();

sqlcommand mycommand = new sqlcommand() ;
mycommand.activeconnection = myconn ;
mycommand.commandtext = "n_addtopic" ; //調用存儲過程
mycommand.commandtype = commandtype.storedprocedure ;
mycommand.parameters.add(new sqlparameter("@a_strtitle" , sqldatatype.varchar,100)) ;
mycommand.parameters["@a_strtitle"].value = n_topic.title ;

mycommand.parameters.add(new sqlparameter("@a_strauthor" , sqldatatype.varchar,50)) ;
mycommand.parameters["@a_strauthor"].value = n_topic.author ;

mycommand.parameters.add(new sqlparameter("@a_strcontent" , sqldatatype.varchar,2000)) ;
mycommand.parameters["@a_strcontent"].value = n_topic.content ;

try


myconn.open() ;
mycommand.executenonquery() ;

//清場

myconn.close() ;

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

}
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南投市| 南岸区| 赣榆县| 淮阳县| 沙洋县| 绥棱县| 白朗县| 中卫市| 邢台市| 尚义县| 武义县| 镇江市| 石泉县| 松原市| 银川市| 德庆县| 鹤山市| 固阳县| 肇东市| 洛川县| 达尔| 体育| 商都县| 天津市| 宿州市| 瑞丽市| 古交市| 沽源县| 余姚市| 兰溪市| 姜堰市| 米林县| 济阳县| 洛隆县| 湖南省| 南昌市| 名山县| 临西县| 武乡县| 新泰市| 沙河市|