Ultradev Example Tutorial: 3.5 Editing Records in the Database
Author:Eve Cole
Update Time:2009-05-30 18:34:45
Chapter 3: Applying Database to Create Dynamic Web Pages
Section 5: Edit records in the database
To edit or delete a record, we first need to know which record we are editing or deleting. Zhang Guanli Dai's words are not the result we want:) When we talked about database design earlier, we specifically mentioned that a table must have a primary key to determine the uniqueness of the record and avoid deletion or editing errors. For example, if we want to find a person named Zhang San, but there are more than a dozen people named Zhang San at the same time, then we have to determine which Zhang San you are looking for based on certain characteristics. The same is true for the primary key, which can be composed of one subsegment or several subsegments. For our userinfo table, the primary key is the automatic numbering field named ID. This ID value is unique, which means that we only need to know an ID to uniquely find a record. In this way, our editing and deletion operations can be normal. carried out.
Okay, after nagging for so long, let’s start our trip.
Let's open the data display page we started with, add two more cells, and make edit and delete connections respectively, as shown in the figure.
The editing link is: edit.asp?id=<%=(Recordset1.Fields.Item("ID").Value)%>
The deleted connection is: del.asp?id=<%(Recordset1.Fields.Item("ID").Value)%>
You may ask, what does this mean? , let me elaborate.
edit.asp?id=<%=(Recordset1.Fields.Item("ID").Value)%>
It means that after clicking this link, a page named edit.asp will be opened, and a parameter named id with a value of <%=(Recordset1.Fields.Item("ID").Value)%> will be passed to this page, and then In the edit.asp page, the corresponding records will be taken out for processing based on the passed parameters.
Friends, have you seen it? <%=(Recordset1.Fields.Item("ID").Value)%> is actually the value of the ID field in our Data Bindings. Each record corresponds to only one unique ID value, which is this <%=(Recordset1.Fields.Item("ID").Value)%> . When edit.asp obtains this value, it can retrieve this record. , as for how to get it, let’s look down. By the way, deleted connections are also processed in this way.
Create a new page and save it as edit.asp. Then we start creating the record set as described above, but this time the record set creation process is a little different, as shown in the figure:
Filter was not used when we created the record set before. As the name suggests, it filters out some data we don't need based on certain conditions. The fields listed in Filter are the fields of your database table. Here we select, and then set the condition to " = ". Then we pull down the selection box under ID, select URL Parameter, and fill in the ID.
Why choose this? Our connection form above is not:
edit.asp?id=<%=(Recordset1.Fields.Item("ID").Value)%> class="coffee">
Well, you can see some clues, edit.asp?id=.... This id is the URL Parameter, it's up to you, as long as we fill it in correctly here. After setting these, it means that our recordset only selects the value of the ID field equal to the value of the id we passed. Of course, because we only passed one value, there will be only one record taken out.
How to modify the record set after taking it out? In fact, it is equivalent to re-inserting the data.
Open the menu Insert -> Live Objects -> Record Update Form
oh! Is it very similar to the Record Insert Form? The only difference is that there is only one more Unique Key Column (unique key field), which is the primary key we have been nagging about for a long time. Select it as the ID field. The next thing It's simple, just follow what we learned in the Adding Records section and modify it until you're satisfied. Don't worry about Defulat Value, the final result is as shown in the figure.
Okay, let's light a lantern - as usual, open the browser to check our results, select the record we just added: dd to edit, as shown in the picture.
Click the Update Record button to jump to the display page. As shown in the picture, our data has been changed. Haha, be happy!
OK, after reading this data editing process, I believe that the deletion operation will not be difficult for you. In the next section, we will explain how to delete data. You can also relax a bit - after all, some parts of this editing record are quite confusing :)