本文为:匆匆一笑 原创,需要转载请保持文章完整性
上一次的代码,相信大家一定学到了很多知识,这次匆匆将代码稍微正规了点,以便实现同样的功能。代码稍微变化,但是执行界面效果完全一样。大家一定要好好揣摩哟,成长就在瞬息。
1、所需要文件列表:
#ccong .mdb ACCESS数据库,当然你可以随便取名字了
show.asp 显示内容,并给出添加数据的表单
add.asp 执行添加数据文件
del.asp 删除数据
edit.asp 编辑旧数据
save.asp 保存编辑过数据
conn.asp 连接数据库,已经从上次的文章中脱离出来
其实你可以把这几个文件整和在一个文件中,但是此处为了简单明了,我们就分开写了。
2、文件源代码:
(1)#ccong .mdb
使用微软ACCESS建立数据库,同时建立表:CcongData,库中字段:
CcongId 自动编号,储存信息顺序
CcongContent 备注,储存信息内容
(2)show.asp
<!--#include file="conn.asp"-->
<%
dim cConGshow '自定义自定义变量
cConGshow="select * from CcongData order by CcongId desc" '按降序排列
set rs_ccong=conn.Execute(cConGshow)
if rs_ccong.eof or rs_ccong.bof then ' 指针是顶部或者底部,当然没有数据了
response.write"没有记录"
else
do while not rs_ccong.eof ' 指针不是顶部也不是底部,当然就有数据了
dim k '自定义变量
for k=1 to 3
response.write "<a title='删除' href=del.asp?id="&rs_ccong("CcongId")&">ID</a>:"&rs_ccong("CcongId")&"<a title='修改' href=edit.asp?id="&rs_ccong("CcongId")&">内容</a>:"&rs_ccong("CcongContent")&" " '用空格把结果分开
rs_ccong.movenext '继续往下移动指针
Next
response.write"<br>" '每行满3条信息自动加<br>--换行的方法
loop
end if
rs_ccong.close '关闭指针,节约资源
set rs_ccong= nothing
%>
<form name="CcongForm" action="add.asp" method="post">
<input type="text" name="CcongContent" size="20">
<input type="submit" name="submit" value="确定">
</form>
(3)add.asp
<!--#include file="conn.asp"-->
<%
CcongContent=trim(request.form("CcongContent")) '注意区别del.asp
if CcongContent="" then
response.write "内容为空"
response.end '强制结束
end if
dim cConGadd '自定义变量
cConGadd="insert into CcongData(CcongContent) values ('" & CcongContent& "')"
conn.execute(cConGadd)
if err.number<>0 then '判断SQL是否成功执行
response.write "出错了"
else
response.Redirect "show.asp" '添加成功,返回show.asp
end if
%>
(4)del.asp
<!--#include file="conn.asp"-->
<%
dim CconGdel
CcongId=request.QueryString("Id") '注意和 add.asp 区别
CconGdel="delete from CcongData where CcongId="&CcongId
conn.Execute(CconGdel) '这里利用Execute方法,删除记录
response.Redirect "show.asp" '返回show.asp
%>
(5)edit.asp
<!--#include file="conn.asp"-->
<%
CcongId=request.QueryString("id")
dim cConGshow '自定义自定义变量
cConGshow="select * from CcongData where CcongId=&CcongId
set rs_ccong=conn.Execute(cConGshow)
CcongContent=rs_ccong("CcongC
| 对此文章发表了评论 |
