Learning purpose: Learn basic database operations 3 (delete records)
Let’s get straight to the point, let’s just look at the program.
exec="delete * from guestbook where id="&request.form("id")
The above sentence completes the operation of deleting the record, but the unique ID of the record is used to lock the record. When we created the database earlier, we used the primary key given to us by the system, and the name is the number. Since the name is in Chinese, it is not very convenient. You can change it to id. If you don’t change it, it will be
exec="delete * from guestbook where number="&request.form("id")
Let's look at the complete code below: a form passes an ID to the ASP file, and then the ASP file deletes the ID.
<form name="form1" method="post" action="example7.asp">
delete:
<input type="text" name="id">
<input type="submit" name="Submit" value="Submit">
</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 number="&request.form("id")
conn.execute exec
%>
I added example72.asp in the example, which is similar to example4.asp, except that an id field is added. You can run this file first to see the IDs of all records and the IDs of the records you want to delete. After deleting the records, you can also use this Document review. By the end of the day, we will put all these things together. You won’t need such troublesome operations.
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>Untitled Document</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("number")%></td>
<td><%=rs("name")%></td>
<td><%=rs("tel")%></td>
<td><%=rs("message")%></td>
<td><%=rs("time")%></td>
</tr>
<%
rs.movenext
loop
%>
</table>
</body>
</html>