// page information $page_type = "t"; $page_title = "Delete Database Records with ASP"; $page_keywords = "asp, database, access, delete, record, html, code, microsoft, connection, connect"; $page_description = "Delete database record with ASP tutorial. Find more tutorials and scripts at TheScripts.com, a programming and software development resource, directory and community."; $page_articletitle = "Deleting Records"; $page_next_url = ""; $page_next_anchor = ""; $page_prev_url = "/serversidescripting/asp/tutorials/aspanddatabases/page3.html"; $page_prev_anchor = "Display Records"; $page_author = "Robert Murdock"; $page_byline = "Programmer, Darpac Inc."; // site header include ($_SERVER["DOCUMENT_ROOT"]."/header.php"); // begin html ?>
And the final step!
Deleting a record. This is very simple delete code. You enter the name of the person that you want to delete. If the name exists in the database then the record gets deleted. If it doesn't exist than no action will be taken.
The first file, delete.html, is the form use to input the name. The form's ACTION attribute must point to the ASP file. In our example it's delete.asp.
File: delete.htm
<html>
<head>
<title>Delete Record</title>
</head>
<body BGCOLOR="#ffffff">
<form ACTION="delete.asp" METHOD="POST">
<div align="left"><p>Please enter the full name that you will delete:<br>
</p>
</div><blockquote>
<div align="center"><div align="center"><center><table border="1" width="512" height="78">
<tr>
<td width="500" height="22" colspan="2">User To Delete:</td>
</tr>
<tr>
<td width="83" height="7">Name</td>
<td width="417" height="7"><input type="text" name="Name" size="20"></td>
</tr>
</table>
</center></div><div align="center"><center><table>
<tr>
<td><div align="center"><center><p><input TYPE="SUBMIT" VALUE="Delete"></td>
</tr>
</table>
</center></div></div>
</blockquote>
</form>
</body>
</html>The ASP code is placed in delete.asp. This file houses the code to delete the record from the database.
File: delete.asp
<html>
<head>
<title>Delete Record</title>
</head>
<body BGCOLOR="#ffffff">
<!--#include file="adovbs.inc"-->
<%
TEMP = Request.form("Name")
Set DataConn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
DataConn.Open "DBQ=" & Server.Mappath("cdemo.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
Set rsDsp = DataConn.Execute("DELETE FROM tblContact WHERE Name = " & TEMP)
Response.Write("<center>Record Deleted.</center>
%>
</body>
</html>