A little summary: the operation of the database is nothing but
displays records, inserts records, modifies records, deletes records, and queries records.
And when it comes to displaying records, it's also about
display output format, paging program, then combined with the insertion of records, a simple news system, article system, message system, registration system does not have any problems.
The following involves managing this piece, requiring modifications to the database records.
first, to change which
Modify, not Station, but to a specific change to the corresponding. It can be vividly said that the database table in the specific line to make specific changes.
So, this time the recordset has a specific one, of course this is mainly determined by the SQL statement.
For example, sql= "select * from table where id=1" means all records for the line that the ID number is extracted is 1, and it's OK to just assign the field that needs to be modified in that row to the new value and then upload the database.
The same statement sql= "SELECT * from table where id=2" believe you can understand.
But as we are in the page, is not so fixed, there are but select a connection, or enter a form value ... Jump to a special modification page, so that all the tasks are on the Modify page, it has the SQL statement should be adaptable
such as sql= "select * from table where id=" &request.queyrstring ("id")
Second, the corresponding assignment that will be modified
It's simple, as with inserting records, to match fields and values.
RS ("cn_name") = "Cnbruce"
RS ("cn_sex") = "male"
The corresponding value, of course, can also be a variable or function
Finally, upload the update database
The same as inserting the rs.updata, in fact, observed, insert new records and update records is only more rs.addnew this line of the statement.
1,showit.asp
The file is a reference established in the previous example. It is mainly the role of display, so now, for a specific record to increase the jump to modify the page hyperlink.
<% For i = 1 to Rs. PageSize ' use for Next loop to read the record of the current page sequentially If Rs. EOF Then Exit for End If Response.Write ("<a href=change.asp?id=" & RS ("cn_id") & "> Modify </a>") Response.Write ("article title is:" & RS ("Cn_title")) Response.Write ("<br> article author is:" & RS ("Cn_author")) Response.Write ("<br> article Add Time is:" & RS ("Cn_time")) Response.Write ("<br> article content is:" & RS ("Cn_content")) Response.Write ("Rs. MoveNext Next %>
|
Attention
Response.Write ("<a href=change.asp?id=" & RS ("cn_id") & "> Modify </a>")
The value of the subsequent parameter ID is dynamic, and then the chang.asp can be seen.
2,change.asp
<!--#include file= "conn.asp"--> <% Id=request.querystring ("id") %>
<%if Request.Form ("submit") = "Change" Then Whattitle=request.form ("title") Whoauthor=request.form ("author") Whatcontent=request.form ("content") Id=request.form ("id") Set rs = Server.CreateObject ("ADODB.") Recordset ") sql = "SELECT * from Cnarticle where cn_id=" &id Rs. Open sql,conn,3,2 RS ("Cn_title") =whattitle RS ("Cn_author") =whoauthor RS ("Cn_content") =whatcontent Rs.update Rs.close Set rs = Nothing Conn.close Set conn=nothing Response.Redirect ("showit.asp") Response.End %> <%end if%>
<% If id<> "" Then Set rs = Server.CreateObject ("ADODB.") Recordset ") Sql= "SELECT * from Cnarticle where cn_id=" &id Rs. Open sql,conn,1,1 Whattitle=rs ("Cn_title") Whoauthor=rs ("Cn_author") Whatcontent=rs ("Cn_content") End If %> <form action= "change.asp" method= "POST" > Title:<input type= "text" name= "title" Value=<%=whattitle%>><br> Author:<input type= "text" name= "Author" value=<%=whoauthor%>><br> Content:<br> <textarea name= "Content" rows= "8" cols= "><%=whatcontent%></textarea><br>" <input type= "Submit" value= "Change" name= "Submit" > <input type= "reset" value= "reset" > <input name= "id" type= "hidden" value= "<%=id%>" > </form>
|
Of course, all the procuratorial, security protection has not done, a lot of bugs, they have to slowly solve.
Another kind of modification update
<%if Request.Form ("submit") = "Change" then Whattitle=request.form ("title") Whoauthor=request.form ("author") Whatcontent=request.form ("content") Id=request.form ("id") sql = "Update cnarticle set cn_title= '" & whattitle& "', cn_author= '" &whoauthor& "', cn_content= '" &whatcontent& "" where cn_id= "&id Conn. Execute (SQL) Conn.close Set conn=nothing Response.Redirect ("showit.asp") Response.End %> |