All ASP Code is in RED
'This page doesn't use a session variable so for performance reasons I set the two directives.
'By Setting the EnableSessionState you save the asp.dll from making a call to the MTS to check
'for Session variables used by this page
<%@ Language = "VBScript" @ ENABLESESSIONSTATE=False %>
<%
'Declare all local variables
dim conn
dim rs
dim strsql
dim strconn
'Set local variable to the connection string and open the connection
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("adoandsqladd.mdb")
set conn = server.createobject("adodb.connection")
conn.open strconn
'Set local recordset variable equal to rs
set rs = server.createobject("adodb.recordset")
'Sets the sql query that determine what records get brought back to the asp page.
'This could easily be change to a very specific set of fields or instead of using a ORDER BY statement
'Using a WHERE statement to determine what records get selected IE(WHERE tblUPDATEADO.id=1)
strsql = "SELECT * FROM tblUpdateADO ORDER BY id"
rs.open strsql, conn
%>
<html>
<head>
<title>signon</title>
</head>
<body>
<h3 align="center">Update w/ADO example</h3>
<td width="10%"><form method="post" name="form1" action="updateado2.asp">
<table>
<%
'Writes out the records, again this could just writing out one record just take away the DO While LOOP
x = 1
rs.movefirst
Do While NOT rs.EOF
%>
<tr><td><strong>First Name</strong></td><td>
<input type="text" size="10" name="FirstName<%= x %>" value="<% = rs("FirstName")%>"></td>
<td><strong>Last Name</strong></td><td>
<input type="text" size="10" name="LastName<%= x %>" value="<% = rs("LastName")%>"></td>
</tr>
<%
x = x + 1
'Don't forget to move the recordset to the next record or your going to have an infinate loop
'Trust me this statement I always forget!
rs.movenext
Loop
%>
<td><input type="Submit" value="Submit Update Example" name"b1"> </font>
</form>
</td></tr>
</table>
</center></div>
</body></html>
Page 2 the page actually re-submits the information back to the database Here is the code that is used to update the information on the demo.
<%@ Language = "VBScript"%>
<%'Declare all local variables
dim conn
dim rs
dim strconn
dim strsql
strsql = ""
'set connection string to local variable
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("adoandsqladd.mdb")
set conn = server.createobject("adodb.connection")
conn.open strconn
'Use the execute method of the connection object the insert the record
'build the sql statement based on the input from the form
For x = 1 to 5
strSQL = "UPDATE tblUpdateSQL " & _
"SET tblUpdateSQL.FirstName = '" & request("FirstName" & x) & "', " & _
"tblUpdateSQL.lastName = '" & request("LastName" & x) & "' " & _
"WHERE (((tblUpdateSQL.id)=" & x & "))"
conn.execute(strSQL)
Next
conn.close
set conn = nothing
%>
<% = "Your record has been added" %>
<p><br>
</p>
<p><a href="updatesql.asp">Click here to return to the start page of the demo</a></p>
Good Luck!!