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>