ASP Hosting - ASP Web Hosting  
ASP Hosting Plans Internet Marketing SQL Hosting Plans Customer Support Contact Us

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. 
<%
'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
Dim lngRecordNo    'Holds the record number to be updated

'Read in the record number to be updated
lngRecordNo = CLng(Request.QueryString("ID"))

'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("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 WHERE ID_no=" & lngRecordNo

'Open the recordset with the SQL query
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">
<!-- Begin form code -->
<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>
<!-- End form code -->
</body>
</html>

<%
'Reset server objects
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