ASP Programming Introduction (20): Modified Data Records of ADO Components

xiaoxiao2021-03-06  39

Come and summarize: The operation of the database is nothing more than displaying records, inserts record, modifying records, delete records, query records. And in the display record, the displayed output format, the paging program, then combined with the insert record, a simple news system, the article system, the message system, and registered landing systems are not any problem. The following is to manage this, you need to modify the database record. First, which modification is to be modified, not a cage, but to modify the corresponding pair of specific pairs. It can be said that specific modifications are made to the specific rows of the database table. So, this time the record set has its specific one, of course, this is mainly determined by the SQL statement. For example, SQL = "Select * from table where id = 1" means that the extracted ID number is all records of the line of 1, and then simply assigns a new value that needs to be modified in this line and then upload the database is OK. The same statement SQL = "Select * from table where id = 2" believes that you can understand. But as we are in the page, it is not to be fixed, there is a choice of a connection, or enter a form value ... Jump to a dedicated modification page, so all the tasks are all on the page, it has The SQL statement should be a strong adaptive such as SQL = "select * from table where id =" & required.Queyrstring ("id") Next, the corresponding assignment to be modified is simple. As inserted into the record, the fields and values ​​correspond to the value. RS ("CN_NAME") = "CNBRUCE" = "" cn_sex ") =" MALE "corresponds to a certain variable or function final, upload update the database and insert RS.UPDATA, actually observed, inserted The new records and update records are just a statement of RS.AddNew. 1. Showit.asp This file is the referenced by the previous example. It is primarily displayed, then now, add a skip to a hyperlink to a modified page for a specific record.

<% For i = 1 to rs.pageSize 'Use the for next loop to read the current page record IF ife.eof kilite ("") Response.write ("Article title is:" & RS ("cn_title") Response.write ("
article author is:" & RS ("cn_author ")) Response.write ("
) Response.write ("
article content is:" & rs ("cn_content") response.write) response.write ("cn_content")) response.write "


") rs.MovenextNext%>

Note that response.write (" Modify ") is dynamic, then look at CHANG .asp can be resistant. 2, change.asp

<% id = request.queryString ("ID")%> <% if request.form ("submit") = "change" thenwhattitle = request.form ("Title") WHOAUTHOR = Request.form ("Author") WhatContent = Request.form ("Content") id = request.form ("id") set = server.createObject ("adoDb.recordset") SQL = "Select * from cnarticle where cn_id =" & idrs.Open sql, conn, 3,2rs ( "cn_title") = whattitlers ( "cn_author") = whoauthorrs ( "cn_content") = whatcontentrs.updaters.close Set rs = Nothingconn.close SET CONN = NothingResponse.Redirect ("Showit.asp") response.end%> <% end if%> <% if id <> "" "" "" "" "adoDb.recordset") SQL = "SELECT * From cnarticle where cn_id = "& id ropen sql, conn, 1, 1 whattitle = rs (" cn_title ") WHOAUTHOR = RS (" cn_author ") WhatContent = RS (" cn_content ") end if%>

title: = whatTITLE% >>
Author: >
Content: