Top » ASP » DELETING A RECORD If you find this page useful
please make a secure donation
My Account  |  Cart Contents  |  Checkout   

Deleting a Record


Deleting a record in your database is very similar to updating, so we're going to use the same code for the first page called users.asp. The only thing that will need changed in the users.asp page is the link for each user. This time, we need to point it to the page that will delete the record. So change the link in your users.asp page from:

<a href='edit.asp?ID=" & RS("userID") & " '>" & RS("username") & "</a> to:
<a href='deleteuser.asp?ID=" & RS("userID") & " '>" & RS("username") & "</a>

And then save this as duser.asp. All we need now is one more page to do the actual deleting, so that's all this tutorial will contain. If you don't know how to create the duser.asp page that we mentioned, check out our previous tutorial on updating a record in a database. Here we go.

After passing the ID of the record we want to delete, we use our DELETE statement.

<% @Language=VBScript%>
<% Option Explicit %>
<!--#include file="adovbs.inc"-->
<!--#include file="connection.asp"-->
<%
Dim ID, objConn, RS, SQL
ID = trim(request("ID"))
Set RS = Server.CreateObject("ADODB.Recordset")
SQL = "DELETE * FROM users WHERE userID = " & ID & " "
RS.Open SQL, objConn
%>
<html>
<head><title>Edit User</title></head>
<body>
You have successfully deleted a user. <a href="duser.asp">Click here</a> to continue.
</body</html>

Not too hard, eh? Have fun, just don't go crazy with it or you won't have a database to work with after too long. Remember to post any questions on our messageboard. See ya next time!

~Geoff Swartz