![]() |
Page 1 of 3
In this session we're going to create 3 pages to update data in the 'Guestbook' database made in the first database session. The first page is used to display the contents of the database so you can select which entry you want to update. The second page uses a form to display the data held in the database table and allows you to edit the data. The third page is used to update those changes in the database.
First we need to create a page to display the contents of the database so we can select which entry that we want to update. <html> <head> <title>Update
Entry Select</title> <body
bgcolor="white"
text="black"> <% 'Dimension
variables Dim
adoCon
'Holds the
Database Connection Object Dim
rsGuestbook
'Holds the
recordset for the records in the database Dim
strSQL
'Holds the SQL
query for the database 'Create an ADO connection object
'Write the
HTML to display the current record in the
recordset
Response.Write
("<br>")
Response.Write
("<a href=""update_form.asp?ID="
& rsGuestbook("ID_no") &
""">")
Response.Write
(rsGuestbook("Name")) Response.Write
("</a>")
Response.Write
("<br>")
Response.Write
(rsGuestbook("Comments"))
Response.Write
("<br>")
'Move to the
next record in the recordset
rsGuestbook.MoveNext Loop Save
this page as 'update_select.asp' in the same folder
as the Guestbook database. Main
Page | Hosting
Plans | E-Commerce
| Sign
Up Now! | Site
Map asp web hosting by HyperlinkHost.com
</head>
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("guestbook.mdb")
'Set an active
connection to the Connection object using DSN
connection
'adoCon.Open
"DSN=guestbook"
'Create an ADO recordset object
Set rsGuestbook =
Server.CreateObject("ADODB.Recordset")
'Initialise the
strSQL variable with an SQL statement to
query the database
strSQL = "SELECT tblComments.* FROM
tblComments;"
'Open the recordset
with the SQL query
rsGuestbook.Open strSQL, adoCon
'Loop through the
recordset
Do While not rsGuestbook.EOF
'Reset server objects
rsGuestbook.Close
Set rsGuestbook = Nothing
Set adoCon = Nothing
%>
</body>
</html>