| 学习目的:学会数据库的基本操作3(删除记录)开门见山,大家直接看程序。
 exec="delete * from guestbook where id="&request.form("id")
 上面这句话完成了删除记录的操作,不过锁定记录用了记录唯一的表示id,我们前面建立数据库的时候用的是系统给我们的主键,名字是编号,由于是中文的名字不是很方便,大家可以修改为id,不修改的话就是
 exec="delete * from guestbook where 编号="&request.form("id")
 下面我们看完整的代码:一个表单传给ASP文件一个ID,然后这个ASP文件就删除了这个ID。
 <form name="form1" method="post" action="example7.asp">
 delete:
 <input type="text" name="id">
 <input type="submit" name="Submit" value="提交">
 </form>
 
 example7.asp:
 <%
 set conn=server.createobject("adodb.connection")
 conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("example3.mdb")
 exec="delete * from guestbook where 编号="&request.form("id")
 conn.execute exec
 %>
 我在示例里面加了一个example72.asp,和example4.asp差不多,就是加了一个id字段,大家可以先运行这个文件看一下所有记录的ID和想删除记录的ID,删除记录以后也可以通过这个文件复查。等到最后一天,我们会把所有的这些东西整合的。大家就不会需要这么麻烦的操作。
 
 example72.asp:
 <%
 set conn=server.createobject("adodb.connection")
 conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("example3.mdb")
 exec="select * from guestbook"
 set rs=server.createobject("adodb.recordset")
 rs.open exec,conn,1,1
 %><html>
 <head>
 <title>无标题文档</title>
 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 </head>
 <body bgcolor="#FFFFFF" text="#000000"> <table width="100%" border="0" cellspacing="0" cellpadding="0"><%
 do while not rs.eof
 %><tr>
 <td><%=rs("编号")%></td>
 <td><%=rs("name")%></td>
 <td><%=rs("tel")%></td>
 <td><%=rs("message")%></td>
 <td><%=rs("time")%></td>
 </tr>
 <%
 rs.movenext
 loop
 %>
 </table>
 </body>
 </html>
 (编辑:宣城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |