Updating Records in a Database in ASP
Download
the code
Below is a table called 'Members_tbl' with 3 rows of data which
belongs to a database called 'Members.mdb'.
Running the code below will update the row where LastName is
equal to Wall and change the value of FirstName to Mike rather
than Michael.
Call our file 'update_record.asp'.
<%@ Language="VBScript" %>
<% Option Explicit %>
<html>
<head>
<title>Updating records in a database table</title>
</head>
<body>
<%
Dim connection, sSQL, sConnString
sSQL="Update Members_tbl SET FirstName='Mike' WHERE LastName='Wall'"
Set connection = Server.CreateObject("ADODB.connection")
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("Members.mdb")
Connection.Open sConnString
Connection.Execute sSQL
Response.write "<div align='center'>The record has been
updated.</div>"
connection.Close
Set connection = Nothing
%>
</body>
</html>
Note also that we haven't used the the recordset object as we
are not returning a recordset, we are simply updating records.
Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.
|