ASP Database Delete
Homepage >
ASP Tutorials >
ASP Database Delete
In the final part of this tutorial we learn how to use ASP to delete from the database.
We start as usual by opening a connection to the database using the Users DSN.
<%
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "DSN=Users"
%>
The SQL query to delete a record is very simple and once again, we'll assume that the User ID has been passed from the previous ASP page:
<%
iUserID = Request.QueryString("UserID")
sSQL = "delete * from Users where ID=" & iUserID
%>
Now all we need to do is execute the query to delete the record. Notice that we don't have to close the Recordset this time - this is done automatically after the record is deleted.
<%
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = oConn
rs.Source = sSQL
rs.Open
%>
We still need to destroy the objects we're used:
<% Set rs = Nothing oConn.Close Set oConn = Nothing %>

