Print Page | Close Window

Update Database Entry

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5255
Printed Date: 30 March 2026 at 7:46pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Update Database Entry
Posted By: Dazz
Subject: Update Database Entry
Date Posted: 24 August 2003 at 4:42pm

Hi,
When I try to update a database entry with the code which i have included below the actual entry isnt updated, instead another page is added, what could be causing this?

Regards - Darrel

<%
'Dimension variables
Dim adoCon            'Holds the Database Connection Object
Dim rsUpdateEntry   'Holds the recordset for the record to be updated
Dim strSQL             'Holds the SQL query to query the database
Dim lngRecordNo      'Holds the record number to be updated
 
'Read in the record number to be updated
lngRecordNo = CLng(Request.Form("ID_no"))
 
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")
 
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("data.mdb")
 
'Create an ADO recordset object
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")
 
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT tblData.message, tblData.PageName, tblData.UpdatedBy FROM tblData WHERE ID=" & lngRecordNo
 
'Set the cursor type we are using so we can navigate through the recordset
rsUpdateEntry.CursorType = 2
 
'Set the lock type so that the record is locked by ADO when it is updated
rsUpdateEntry.LockType = 3
 
'Open the recordset with the SQL query
rsUpdateEntry.Open strSQL, adoCon
 
'Update the record in the recordset
rsUpdateEntry.Fields("ID")
rsUpdateEntry.Fields("message") = Request.Form("message")
rsUpdateEntry.Fields("PageName") = Request.Form("PageName")
rsUpdateEntry.Fields("UpdatedBy") = Request.Form("PageAuthor")
 
'Write the updated recordset to the database
rsUpdateEntry.Update
 
'Reset server objects
rsUpdateEntry.Close
Set rsUpdateEntry = Nothing
Set adoCon = Nothing
 
'Return to the update select page in case another record needs deleting
Response.Redirect "default.asp?pupdated=true"
%>




Replies:
Posted By: Bunce
Date Posted: 24 August 2003 at 5:21pm

Dazz,

If you are updating data in a database and you don't need to display it on your in the same request, then there's no need to open a recordset and pull all that data in from the web site.

What you need to do is construct a SQL query such as the one found here:
http://www.w3schools.com/sql/sql_update.asp - http://www.w3schools.com/sql/sql_update.asp

and simply execute it against an existing connection:

strSQL = "UPDATE myTable SET..... "
adoConn.execute(strSQL)

Cheers,
Andrew

Cheers,
Andrew



-------------
There have been many, many posts made throughout the world...
This was one of them.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net