3)postmessage.aspx: - 将数据保存到数据库的页面
<%@ incort namespace = system%>
<%@汇编名称= system.data%>
<%@ incort namespace = system.data%>
<%@ import namespace = system.data.ado%>
<%@ page语言= c#debug = true%>
<html>
<头>
<title>谢谢您的发布!</title>
<脚本语言= C#runat =服务器>
//页面加载时执行此脚本
void page_load(object src,eventargs e)
{
//如果页面从另一个页面调用
如果(!page.ispostback){
//从查询字符串获取所有参数
字符串名称= request.params [name];
字符串电子邮件= request.params [email];
字符串主题= request.params [主题];
字符串ip = request.params [ip];
字符串日期= request.params [date];
字符串消息= request.params [message];
bool newmess = true;
字符串previd = 1;
//检查帖子是新主题还是对新主题的答复
if(request.params [newpost] .equals(no))
{
//如果答复,请在此处获取perpid as previd
newmess = false;
previd = request.params [pavid];
}
//如果帖子是一个新主题,请遵循以下例程
如果(newmess)
{
//数据库路径的字符串,如果您的数据库在某些其他
目录然后编辑路径
//此变量
字符串[电子邮件保护]提供商= microsoft.jet.oledb.4.0;数据源=
+server.mappath(.// db // board.mdb);
//获得数据库的胶合连接
Adoconnection myConn =新的adoconnection(strconn);
// SQL选择语句
字符串strcom =从newpost中选择postid;
//创建一个adocommand,因为我们希望以后使用adodatareader
adocommand mycommand = new adocommand(strcom,myconn);
//打开连接
myconn.open();
adodatareader读者;
//执行命令并将数据输入阅读器
mycommand.execute(out Reader);
int i = 1;
//获取数据库中当前存在的记录。
while(reader.read())
{
i ++;
}
reader.close();
//构建SQL语句以插入数据库
字符串insertstr =插入newPost值(
+i +,'
+名称+','
+电子邮件+','
+主题+','
+ip+','
+date+','
+消息+',0,0);
mycommand.commandText = insertstr;
//由于SQL语句未返回任何输出使用executenonquery()方法
mycommand.executenonquery();
//关闭连接
myconn.close();
}
别的
{
//如果发布的数据是对主题的答复,请按照以下步骤操作
//字符串的数据库路径,如果您的数据库存储在其他目录中,则
//在这里编辑路径
字符串[电子邮件保护]提供商= Microsoft.jet.oledb.4.0;数据源=+
server.mappath(.// db // board.mdb);
Adoconnection myConn =新的adoconnection(strconn);
// SQL语句选择回复ID
字符串strcom =从回复中选择回复;
//创建一个adocommand
adocommand mycommand = new adocommand(strcom,myconn);
//打开连接
myconn.open();
adodatareader读者;
//执行命令并将数据输入阅读器
mycommand.execute(out Reader);
int i = 1;
//获取数据库中当前存在的记录。
while(reader.read())
{
i ++;
}
reader.close();
//构建一个语句以将值插入回复表中
字符串insertstr =插入回复值(
+i +,'
+名称+','
+电子邮件+','
+主题+','
+ip+','
+date+','
+消息+',
+previd+);
mycommand.commandText = insertstr;
// executenonquery-由于命令没有返回任何内容
mycommand.executenonquery();
//字符串从NewPost表获取回复列
字符串ReplyNo =从newpost中选择postid =+pravid;
mycommand.commandText = ReplyNo;
//执行命令并获取读者
mycommand.execute(out Reader);
//阅读第一个记录(请记住,读者只能有一个记录,因为PostID是唯一的)
reader.read();
//从newpost表中的回复列中获取答复列的INT16值
int rep = reader.getInt16(0);
reader.close();
rep ++;
// SQL语句更新NewPost表中的回复字段
字符串UPDTSTR = UPDATE NEWPOST SET回复= +REP
+其中(postid = +previd +);
mycommand.commandText = updtstr;
//执行Enecutenonquerry为什么?我想你现在应该知道!
mycommand.executenonquery();
myconn.close();
}
//从查询字符串获取不同的参数并将其存储
//到各自的标签
namelabel.text = name;
emaillabel.text =电子邮件;
objectlabel.text =主题;
messagelabel.text =消息;
}
别的
{
//其他显示错误
errmess.text =无法直接调用此页面。必须从表单发布页面中调用。<br>;
}
}
</script>
<link href = mystyle.css type = text/css rel = stylesheet>
</head>
<身体topmargin = 0 leftmargin = 0 rightmargin = 0 marginwidth = 0 marginheight = 0>
<! - #include file = header.inc->
<center>
<asp:label id = errmess text = style =颜色:#ff0000 runat = server />
<H2 class = fodark> <b>谢谢您在留言板上发布。</b> </h2>
<table align =中心宽度= 60%边界= 0 cellpacing = 2 cellpadding = 1>
<tr class = fohead> <td colspan = 2>您发布的信息!</td> </tr>
<tr class = folight>
<td>名称:</td>
<td> <asp:label id = namelabel text = runat = server /> < /td>
</tr>
<tr class = folight>
<TD>电子邮件:</td>
<td> <asp:label id = emaillabel text = runat = server /> < /td>
</tr>
<tr class = folight>
<td>主题:</td>
<td> <asp:label id = objecterlabel text = runat = server /> < /td>
</tr>
<tr class = folight>
<TD>消息:</td>
<td> <asp:label id = messagelabel text = runat = server /> < /td>
</tr>
</table>
<br>
<H4 class = fodark> <a href = forum.aspx>单击此处</a>返回论坛。<br>
<% - 一点点工作以显示链接以返回页面,如果帖子是回复 - %>
<%if(request.params [previd]!= null)
{%>
<a href ='回复。
你来自哪里。
<%}%>
</h4>
</center>
<! - #include file = footer.inc->
</body>
</html>