Recommended: Asp query record Asp query records: Learning purpose: Learn the basic operations of the database - In the fourth day of query records, we used the following program: We query all records, but when we want to modify and delete records, we cannot be all records, we need to learn to retrieve appropriate records. First look at a statement: a=aaa b=1111110 exec=select * from guest
Asp Modify Records:
Learning purpose: Learn the basic operations of the database - modify records
Let’s look at the code first: (Save as exam8.asp)
<%
set conn=server.createobject(adodb.connection)
conn.open driver={microsoft access driver (*.mdb)};dbq=&server.mappath(data/guestbook.mdb)
exec=select * from guest where id=&request.form(id)
set rs=server.createobject(adodb.recordset)
rs.open exec,conn
%>
<form name=form1 method=post action=modifysave.asp>
<table width=748 border=0 cellpacing=0 cellpading=0 cellpadding=0>
<tr>
<td>name</td>
<td>tel</td>
<td>message</td>
</tr>
<tr>
<td>
<input type=text name=name value=<%=rs(name)%>>
</td>
<td>
<input type=text name=tel value=<%=rs(tel)%>>
</td>
<td>
<input type=text name=message value=<%=rs(message)%>>
<input type=submit name=Submit value=submit>
<input type=hidden name=id value=<%=request.form(id)%>>
</td>
</tr>
</table>
</form>
<%
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
There is no problem with analyzing this code. The function of this code is to accept the ID of the previous page and display the record. The text box is the input place and the display place. If you need to modify it, press Submit it after modifying it; if you do not need to modify it, you can directly press the Submit button.
Here, because this tutorial is suitable for beginners, I also give the submitted form content and save the following code as an 8.htm file
<form name=form1 method=post action=exam8.asp>
Please enter the ID of the record you want to modify:
<input type=text name=id>
<br>
<input type=submit name=submit value=submit>
</form>
There is another thing that has not been mentioned before, that is, the hidden form element: the hidden element. The value inside is not input by the user and will be submitted along with the form to pass variables.
Here is the code for modifysave.asp:
<%
set conn=server.createobject(adodb.connection)
conn.open driver={microsoft access driver (*.mdb)};dbq=&server.mappath(data/guestbook.mdb)
exec=select * from guest where id=&request.form(id)
set rs=server.createobject(adodb.recordset)
rs.open exec,conn,1,3
rs(name)=request.form(name)
rs(tel)=request.form(tel)
rs(message)=request.form(message)
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
Here, the parameters after rs.open exec,conn,1,3 are 1 and 3. I mentioned before that when modifying records, you need to use 1 and 3. In fact, it is easy to understand to modify the record. The record set is rs. rs(aa) is what is currently recording the aa field. Let it equal to the new data request.form(aa) of course be modified, but don't forget to save it in the end, that is rs.update!
Speaking of this, the search, reading, modification, and insertion of records are all said. Through this most basic thing, you can create complex things. The large database outside: the news system, and the guest book is just a little more fields. The code in today's example is combined with the previous database. I will go back to debug and analyze it later.
The process of testing for everyone: first run the 8.htm file
After clicking Submit, modify the record in the following figure
After modification, click Submit, as shown in the figure below, indicating that the modification has been successfully
You can use the previous duqu.asp to show whether it has been successfully modified
Share: Asp write record aspWrite records: Learning purpose: Learn the basic operations of the database--The basic operations of writing records database are nothing more than: query records, write records, delete records, and modify records. Today we will learn to write records first. First create a form: (Save the following article as 5.htm) form name=form1 method=post action=exa5.asp name input type=text