ASP Pages - Editing Records
Page
2 of 3
Entering the Data into a Form to be Updated
In step 2 of this session we need to create a form containing the database fields that we want to update. From this form we can change the details of the record from the database.
The first part of this page is where we connect to the database and read the data into the recordset.
<%
Dim adoCon
Dim rsGuestbook
Dim strSQL
Dim lngRecordNo
lngRecordNo =
CLng(Request.QueryString("ID"))
Set adoCon =
Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft
Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("guestbook.mdb")
Set rsGuestbook =
Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT tblComments.* FROM
tblComments WHERE ID_no=" &
lngRecordNo
rsGuestbook.Open strSQL, adoCon
%>
|
|
As you can see in the code above we haven't closed the recordset yet, so we can
read in the data from the recordset into the default values of the text boxes in
the form. At the end of the page we close the recordset and reset the server
objects.
|
<html>
<head>
<title>Guestbook Update
Form</title>
</head>
<body bgcolor="white"
text="black">
<form name="form"
method="post" action="update_entry.asp">
Name: <input
type="text"
name="name" maxlength="20"
value="<% =
rsGuestbook("Name")
%>">
<br>
Comments: <input
type="text"
name="comments" maxlength="60"
value="<% =
rsGuestbook("Comments")
%>">
<input
type="hidden" name="ID_no"
value="<% =
rsGuestbook("ID_no")
%>">
<input
type="submit"
name="Submit"
value="Submit">
</form>
</body>
</html>
<%
rsGuestbook.Close
Set rsGuestbook = Nothing
Set adoCon = Nothing
%>
|
|
Save
this page as 'update_form.asp' in the same folder as
the Guestbook database.
<<
Back
Continue
>>
Main
Page | Hosting
Plans | E-Commerce
| Sign
Up Now! | Site
Map
asp web hosting by HyperlinkHost.com