十天学会ASP之第七天

王朝asp·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

学习目的:学会数据库的基本操作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>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航