When you want to modify a database in the ASP, I think most people's practices are: get the data you want to modify with RecordSet, write the value of the Field to the value of each form object, to save, from the form object from the form object one by one Read the value, give another one by one. The simplest typical code is as follows:
The initial display code is approximately as follows: <% DIM SQL DIM RS, CN
SQL = "SELECT * from Table Where PRIMARYKEY = 1"
... 'Get Recordset
Dim Svalue (20) Svalue (1) = RS ("COL1") Svalue (2) = RS ("COL2") .... 'assignment%>
> ...
The saving code is approximately as follows: <% DIM SQL DIM RS, CN
SQL = "SELECT * from Table Where PRIMARYKEY = 1"
... 'Get Recordset
RS ("COL1") = Request ["Field1"] RS ("Col2") = Request ["Field2"] ... 'other assignment
Rs.Update ()%>
I used to do it before. But when I met a similar task with a similar task, I found that 80% of the code is similar, and this practice has a lot of inconvenient places: 1. Increase and modify simply use the same process, just indicate It is increasing or modified. This part can be standardized. 2. Display code and save code, is consistent when taking data, when doing ASP, I am accustomed to displaying is a page, handling another page, so simply, and is conducive to code and interface separation. But the maintenance of the code is a bit troublesome. After the code of the data is changed, you must synchronize. 3. When it is judged in the saving code, it is necessary to return the display interface and make a tip. It is also a troublesome thing to keep the user's original value. ASP.NET processing is quite convenient under Post-Back structures. 4. When the form object is Radiobutton, CheckBox or LIST, you should select the corresponding value. This process is also roughly the same, and troublesome. 5. When the Field in the table is much, it is a long value to the table and takes a long from the form. Once there is a change, it is very bad. 6. There should be a lot of inconvenient places.
When I use ASP.NET, I found that APS.NET will be quite good, and the code is excellent. The architecture of the entire application is more reasonable, and it is true in applications. leap. But there are still many programs that need to use ASP, and ASP.NET is very large, and the ASP has a big difference. In order to simplify the database operation in the ASP, the application system is reasonably, I tried to do some improvements, with reference to the thinking of ASP.NET, using single page mode (POST-BACK, very simple). I want to solve it. Problem: 1. When post-back, the form object holds the value input by the last user, and when the enableViewState is similar to the ASP.NET. You can handle the Radiobutton, Checkbox, and DropdownList form objects. 2. You can get the object name that triggers the POST-BACK, an event processing structure that simulates ASP.NET. Of course, it will not be automatically implemented and it needs to be implemented. 3. In the form naming specification, automatically fill in the form object by the Recordset, or fill in the value of the form back into the Recordset. Also supports Radiobutton, Checkbox, and DropDownList form objects.
★ Form Name Specification: "COL_" field name. If there is a field col1 in Table table, the corresponding form is named col_col1
The current sample is placed in the following address: http://www.ccpithz.org/sample/, where the increased and modification page (edit.asp) is used to improve the improvement.
The complete edit.asp page code is as follows: ************************** Edit.asp begin ********* *********************************************************** ************* <% 'declared public variable DIM CN DS DIM Stitle, Sinfo
Page_load
Sub Page_Load () '********************************************************************************************************************************************************************************************************************************************************************************************* **************** The information "***************************************** ***************************** A ID value DIM NID NID = CLNG (Request ("SELECTEDID"))
DIM SSQL, SCONN DIM CNT SCONN = getcommoncnstr () Get database connection string ssql = "select * from article where id =" select * 'retrieved data set cn = server.createObject ("adodb.connection") CN. Open (sconn)
Set DS = New CDataStore DS.INIT CN, SSQL
'First accessing the surface, fill the form from the database, and at Post-Back, you will automatically keep the last form value. If not ispostback () Then BindData Endiff () THEN SAVE END IF SUB ("SAVE") THEN SAVE END IF
Sub Save 'Default DS.GetParam () if Ds.nmode = 1 Then Ds.m_rs ("BJ_SORT") = 9999 End IF
DIM NRC NRC = DS.UPDATE () Stitle = "Modify the file" SINFO = "Data has been saved" End Sub
Sub binddata ds.setparam () if Ds.nmode = 1 dam = "Create a file" DS.M_Value.add "rq", formatdate (now (), 4) Else Stitle = "Modify the file" end if End Sub