摘要:
教程:ASP+SQL Server制作留言板的完整小例子,写写关于SQL Server数据库的简单使用过程的教程,也算一个小总结!记录一些常用的方法,关键字,单词等,供以后查阅用!我们用ASP+SQL Server做个简单的留言板为例!关键字:
ASP SQL Server 留言板 正文:
复的哪条记录,给回复者看
output=output&rs("content")
output=output&"<br><br>"
sqlsub="select * from subFeedback where Feedback_ID="&rs("Feedback_ID")
Set rsSub=Server.CreateObject("ADODB.Recordset")
rsSub.open sqlSub,conn,1,3
if not rsSub.eof then
j=1 '为for语句定义变理
do while not rsSub.eof
for k=1 to j '贴子缩进,贴子越靠后,缩进量越大
output=output&" "
next
output=output&"["&j&"]楼<span style='word-wrap: break-word;'>"
output=output&rsSub("content")
output=output&"</span><br>"
j=j+1
rsSub.movenext
loop
end if
output=output&"<br>"
rs.movenext
loop
response.write output
else
response.write "无记录!"
end if
rs.close
set rs=nothing
%>
<script>
function chkform(){
//这个函数用来判断输入是否为空
//当然这里的判断还远远不够,比仿说还要判断字符的多少,是否有非法字符等
if (document.add.title.value==""|| document.add.content.value==""){
alert("标题或内容不能为空,请输入!");
return;
}
document.add.action="add.asp";
document.add.submit;
}
</script>
<form name="add" method="post" action="javascript:chkfrom();">
标题<input type=text size="50" name=title><br>
内容<textarea name="content" cols="50" rows="8"></textarea><br>
<input type="hidden" value="Feedback" name="table">
<!--上面是一个隐藏域,传递一个名为table,值为Feedback变量,让add.asp知道是编辑的Feedback表-->
<input type="submit" name=submit value=" 提 交 ">
</form>
通过上面的list.asp文件,这时如果数据库有有数据,那么网页中就可以显示数据了,如果没有内容网页显示“无记录”,下边显示增加表单。
3、创建Feedback.asp文件,用来填写留言的回复! 回复:<%=request("title")%>
<form name="add" method="post" action="add.asp">
内容<textarea name="content" cols="50" rows="8"></textarea><br>
<input type="hidden" name="table" value="subFeedback">
<input type="hidden" name="Feedback_ID" value='<%=request.QueryString("Feedback_ID")%>'>
<input type="submit" name=submit value=" 提 交 ">
</form>
4、创建add.asp文件,用来分别保存时Feedback,subFeedback的两个表的增加记录!这里请注意ASP调用SQL SERVER的存储过程的方法,会让程序变的很简洁! <!--#include file="conn.asp"-->
<%
table=request.form("table") '用来判断是编辑的
[1][2][3][4]