Tutorial | 10 Days of learning
Previous section: query Records
Learning Objectives: Learn the basics of database operations--delete records
Straight to the point, everyone directly to see the program.
exec= "Delete * from guest where id=" &request.form ("id")
The above sentence completes the operation of deleting records, however, the lock record with the record unique ID, we set up the database in front of the system to our primary key, the name is number, because the name is not very convenient, we can modify the ID, I have modified Ah!
Without modification, the following code is used:
exec= "Delete * from guestbook where number =" &request.form ("id")
Here we look at the complete code: a form passed to the ASP file an ID, and then this ASP file deleted this ID.
7.htm:
<form name= "Form1" method= "Post" action= "exam7.asp" >
Please enter the ID number of the deletion:
<input type= "text" name= "id" >
<input type= "Submit" name= "Submission" value= "submitted" >
</form>
exam7.asp: ( You can run this file to see the ID of all records and the ID of the record you want to delete, and you can check it later by deleting the record.) )
<%
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Data/guestbook.mdb")
Exec= "SELECT * FROM Guest"
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open exec,conn,1,1
%>
<title> Untitled Document </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body bgcolor= "#FFFFFF" text= "#000000" >
<table width= "100%" border= "0" cellspacing= "0" cellpadding= "0" >
<%
Do as not rs.eof
%><tr>
<TD><%=RS ("id")%></td>
<td><%=rs ("name")%></td>
<td><%=rs ("tel")%></td>
<td><%=rs ("message")%></td>
<td><%=rs ("Time")%></td>
</tr>
<%
Rs.movenext
Loop
%>
</table>
</body>
Next section: Modify a record