Codefixer - ASP tutorials, resources and software
ASP.NET Hosting with US & UK Data Centers!
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Monday 6 October
MembersPro PayPal - ASP Membership software

New MS SQL 2008 Available – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

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'.

Order By

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>
<%
'declare your variables
Dim connection, sSQL, sConnString

'declare SQL statement that will query the database
sSQL="Update Members_tbl SET FirstName='Mike' WHERE LastName='Wall'"

'create an ADO connection object
Set connection = Server.CreateObject("ADODB.connection")

'define the connection string, specify database
'driver and the location of database
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("Members.mdb")

'Open the connection to the database
Connection.Open sConnString

'execute the SQL
Connection.Execute sSQL

Response.write "<div align='center'>The record has been updated.</div>"

'Now close the connection object
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.

Previous: DELETE Records
LinksPro - Directory  and Link  Management Software




ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software