2)回复aspx:主題查看和答复頁面
<%@ page語言= c#enablesessionState = false debug = true%>
<%@ incort namespace = system%>
<%@彙編名稱= system.data%>
<%@ incort namespace = system.data%>
<%@ import namespace = system.data.ado%>
<html> <head>
<title>發布新主題。</title>
<% - 這些是所需的進口組件和名稱空間 - %>
<腳本語言= c#unarat = server>
數據集DS,RS;
Datarow DR;
字符串postid;
public void page_load(對象發送者,EventArgs e)
{
//檢查頁面是否已發布
如果(!page.ispostback)
{
//從查詢字符串獲取帖子
postid = request.params [postid];
如果(postid!= null)
{
//數據庫連接字符串。如果您還有其他路徑,請更改數據庫文件的路徑
//您要保存數據庫文件
字符串[電子郵件保護]提供商= Microsoft.jet.oledb.4.0;數據源=+Server.mappath(.///db // db // board.mdb);
//與數據庫建立連接
Adoconnection myConn =新的adoconnection(strconn);
//字符串從NewPost表中選擇記錄
字符串strcon =選擇主題,名稱,電子郵件,消息,date date vrom newpost where postID =+postid;
//設置一個adodatasetCommand
adodatasetCommand mycommand = new adodatasetCommand(strcon,myconn);
ds = new DataSet();
//永遠不要忘記打開連接
myconn.open();
//填寫數據集
mycommand.filldataset(DS,newpost);
//在位置“ 0”中獲取行,然後將其存儲在datarow對像中
//為什麼在位置“ 0”上劃線?由於給定的帖子只能有一個記錄,請記住!
//為什麼要放入datarow?它易於從datarow訪問數據
dr = ds.table [newpost] .Rows [0];
//從dataRow獲取主題,並將其設置在帖子回复表的主題字段中
object.text = re:+dr [object] .tostring();
//從回复表中選擇對帖子的答复
strcon =選擇名稱,電子郵件,主題,消息,從where postid =+postid到where;
//為答复表製作新的adodatasetCommand和數據集
adodatasetCommand mycommand2 = new adodatasetCommand(strcon,myconn);
rs = new DataSet();
//填寫數據集
mycommand2.filldataset(rs,回复);
//代碼以更新NewPost表的視圖字段
//從表中選擇給定帖子的視圖字段
strcon =從newpost中選擇視圖,其中postid = +postid;
//在這裡製作一個adocommand,因為我們想要一個adodatareader
adocommand vicomm =新的adocommand(strcon,myconn);
adodatareader讀者;
//執行語句並創建一個adodatareader
vicomm.execute(out Reader);
//閱讀第一個記錄(只能有一個記錄記住!)
reader.read();
//從第一列獲取INT32值(我們在讀者中有一個列,請檢查上面的選擇語句)
int i = reader.getInt32(0);
//增加觀點數量
i ++;
reader.close();
//更新具有新視圖值的NewPost表
strcon = update newPost set views = +i +where(postID = +postid +);
//由於我們也使用相同的adocommand對象為此語句設置commandText屬性
vicomm.commandText = strcon;
//由於此語句將不會導致輸出,我們使用executenonquery()方法
vicomm.executenonquery();
//關閉連接
myconn.close();
}
}
}
//單擊“提交”按鈕時,此方法被調用
public void spist_click(對象發送者,EventArgs e)
{
//獲取郵政
postid = request.params [postid];
//僅在填寫所有必需字段時才繼續
if(page.isvalid && name.text!= && objectes.text!= && email.text!=){
dateTime現在= dateTime.now;
errmess.text =;
//我們必須使用查詢來調用postmessage.aspx頁面,以將數據發佈到數據庫中。
//因此,我們必須首先從用戶發布的數據構建自定義查詢
//由於我們使用查詢,我們必須將數據編碼為UTF8格式
字符串req = name =+ system.web.httputitions.urlencodetostostring(name.text,system.text.encoding.utf8);
req+ = && emair =+ system.web.httputity.urlencodeTostoString(email.text,system.text.encoding.utf8);
req+= && objection =+system.web.httputility.urlencodetostostring(object.text,system.text.encoding.utf8);
req+= && ip =+system.web.httputitials.urlencodetostring(request.userhostaddress.tostring(),system.text.encoding.utf8);
req+ = && date =+ system.web.httputility.urlencodetostostring(now.tostring(),system.text.encoding.utf8);
req+ = && message =+ system.web.httputity.urlencodeTostoString(message.text,system.text.encoding.utf8);
//編碼否以表明該帖子不是新帖子,而是對早期消息的答复
req+ = && newpost =+ system.web.httputity.urlencodetostostring(no,system.text.encoding.utf8);
req+ = && previd =+ system.web.httputility.urlencodetostostring(postid,system.text.encoding.utf8);
//使用我們的自定義查詢來調用後消息頁面
page.navigate(postmessage.aspx? + req);
}
別的
{
errmess.text =填寫所有必需的字段! ;
}
}
</script>
<link href = mystyle.css type = text/css rel = stylesheet> </head>
<身體topmargin = 0 leftmargin = 0 rightmargin = 0 marginwidth = 0 marginheight = 0>
<% - 包括標頭文件'header.inc' - %>
<! - #include file = header.inc->
<br>
<div align =中心>
<table border = 0寬度= 80%cellspacing = 2>
<tr class = fohead> <th width = 20%>作者名稱</th>
<th寬度= 80%>消息</th> </tr>
<% - 在下面我將作者的電子郵件封裝在作者的名稱上
這樣,當您單擊作者時,將電子郵件發送給他
另外,我正在從數據庫中獲得日期時間,並分別顯示日期和時間 - %>
<tr class = folight> <td rowspan = 2 align = center> <%= <a href = mailto:+dr [email]+>+dr [name]+</a>%> <br>
<font size = 1> <%= dr [date] .tostring()
<%= dr [date] .toString()。todateTime()。toshortTimestring()%> </font>
</td>
<td> <b>主題:</b> <%= DR [主題]%> </td> </tr>
<tr class = folight>
<td> <pre> <%= dr [message]%> </pre> </td>
</tr>
<% - 獲取所有答復到原始帖子並向他們展示 - %>
<%int no = rs.table [reply] .Rows.Count;
if(no> 0)
{
for(int j = 0; j <no; j ++)
{
datarow rd = rs.table [reply] .Rows [j];
%>
<tr class = fodark>
<td align =中心> <%= <a href = mailto:+rd [email]+>+>+rd [name]+</a>%> <br>
<font size = 1> <%= rd [date] .toString()。todateTime()。toshortDateString()%> <br>
<%= rd [date] .toString()。todateTime()。toshortTimestring()%> </font>
</td>
<td> <pre> <%= rd [message]%> </pre> </td>
</tr>
<%
}
}
%>
</table>
</div>
<h3 align =中心級= fodark> <a href = forum.aspx>單擊此處</a>返回論壇。
<br>回复上述帖子。</h3>
<br>
<asp:label id = errmess text = style =顏色:#ff0000 runat = server />
<form unat = server>
<table border = 0width = 80%align =中心>
<tr>
<td class = fohew colspan = 2> <b>回复帖子</b> </td>
</tr>
<tr class = folight>
<td>名稱:</td>
<td> <asp:textbox text = id = name unat = server/> <font color =#ff0000>*</font> </td> </font> </td>
</tr>
<tr class = folight>
<TD>電子郵件:</td>
<td> <asp:textbox text = id = email runat = server/> <font color =#ff0000>*</font> </td>
</tr>
<tr class = folight>
<td>主題:</td>
<td> <asp:textbox test = id =主題width = 200 runat = server/> <font color =#ff0000>*</font>
</td> </tr>
<tr class = folight>
<TD>消息:</td>
<td>
<asp:textbox id = message runat = server
列= 30行= 15 textmode = Multiline> </asp:textbox> </td>
</tr>
<tr class = folight>
<td colspan = 2>
<asp:button class = fodark id = write onclick = submit_click runat = server text = submit> </asp:button> </td> </td> </tr>
</table>
</form> <br>
<br> <! - #include file = footer.inc->
</body> </html>