Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Update Database Entry
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Update Database Entry

 Post Reply Post Reply
Author
Dazz View Drop Down
Newbie
Newbie
Avatar

Joined: 24 January 2003
Location: United Kingdom
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote Dazz Quote  Post ReplyReply Direct Link To This Post Topic: Update Database Entry
    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"
%>

Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post 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

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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.