Learning Objectives: Learn the basic operation of the database 4 (Modify records)
First look at the code:
<%
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Test.mdb")//This is not a previous database, which aa,bb two fields
Exec= "SELECT * from Test where id=" &request.querystring ("id")
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open Exec,conn
%>
<form name= "Form1" method= "Post" action= "modifysave.asp" >
<table width= "748" border= "0" cellspacing= "0" cellpadding= "0" >
<tr>
<td>aa</td>
<td>bb</td>
</tr>
<tr>
<td>
<input type= "text" name= "AA" value= "<%=rs" ("AA")%> ">
</td>
<td>
<input type= "text" name= "BB" value= "<%=rs" ("BB")%> ">
<input type= "Submit" name= "Submission" value= "submitted" >
<input type= "hidden" name= id "value=" <%=request.querystring ("id")%> ">
</td>
</tr>
</table>
</form>
<%
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
%>
We should now analyze this code is not a problem, the role of this code is to accept the previous page ID and then display this record, the text box is the input of the place is also displayed, if you need to modify the words to submit after the change, if you do not need to modify the Submit button can be directly. Here's another thing that hasn't been said before, that's the hidden form element: The hidden element, where the value is not entered by the user, and is submitted as a single table for passing variables. Here is the code for modifysave.asp:
<%
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Test.mdb")
Exec= "SELECT * from Test where id=" &request.form ("id")
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open exec,conn,1,3
RS ("AA") =request.form ("AA")
RS ("BB") =request.form ("BB")
Rs.update
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
%>
here, the records of the search, read, modify, insert all said, through the most basic things can make complex things, the outside of the large database: News system, the guest book is a little more than the field. Today's example of the code is combined with the previous database, everyone down after the debugging analysis. (RAR inside the example72.asp or for everyone to query the record ID and check the modified records)
here, the Rs.Open exec,conn,1,3 after the argument is 1, 3, which I have mentioned before, modify the record will use 1, 3. In fact, modify the record is easy to understand, the Recordset is Rs,rs ("AA") is the current record AA field of things, let it equal to the new data Request.Form ("AA") of course modified, but finally don't forget to save, that is rs.update!