Ultradev Instance Tutorial: 3.5 Editing records in a database

Source: Internet
Author: User
Tags filter insert key unique id
Tutorials | data | database Chapter III: Application database to create dynamic Web pages

section Fifth: Editing records in a database

To edit or delete a record, first we need to know which record we are editing or deleting. Confusedly's words are not the result we want:) When you talk about database design, it is particularly mentioned that a table must have a primary key to determine the uniqueness of the record, so that it does not cause deletion or editing errors. For example, we want to find a person called John, but at the same time there are a dozen people called John, so we have to according to certain characteristics to determine which Zhang Sanzai is what you are looking for. The same is true for primary keys, which can consist of a single paragraph or a few child segments. For our userinfo table, the primary key is an AutoNumber field called ID, which is unique, which means that we can only find a single record with an ID, so that our edit delete operation can proceed normally.

Well, after a long nagging, let's start our trip.

Let's open the page where we started the data display and add two more cells, respectively, to edit and delete the connection, as shown.

The edited connection is: edit.asp?id=<%= (Recordset1.Fields.Item ("id"). Value)%>

The deleted connection is: del.asp?id=<% (Recordset1.Fields.Item ("id"). Value)%>

You have to ask, what does that mean? , let me take a thin line.

edit.asp?id=<%= (Recordset1.Fields.Item ("id"). Value)%>

This will open the page named edit.asp when clicked, and pass a name ID to the page with a value of <%= (Recordset1.Fields.Item ("id"). Value)%>, and then in edit.asp this page will be processed by taking the corresponding records according to the parameters of the passing past.

Friends see no, <%= (Recordset1.Fields.Item ("ID"). Value)%> is actually the value of the ID field in our data bindings. Each record corresponds to a unique ID value, which is the <%= (Recordset1.Fields.Item ("ID"). Value)%>, when the edit.asp get this value can take out this record, as to how to take, let us look down. By the way, the connection to the deletion is also done with this.



Create a new page, save it as edit.asp, and then we start creating the recordset as described above, but this time the recordset creation process is different, as shown in the figure:



We didn't use filter before we created the recordset. As the name suggests, it is based on certain conditions to filter out some of the data we do not need. Filter is listed in your database table fields, where we select, and then set the condition to "=", then we pull down the selection box below the ID, select the URL Parameter, fill in the ID.

Why do you choose this? Above our connection form is not:

edit.asp?id=<%= (Recordset1.Fields.Item ("id"). Value)%> class= "Coffee" >

, see the clue to come, edit.asp?id= ... This ID is the URL parameter, it is with you, as long as we fill in here. After setting these, our recordset only selects the value of the ID field equals the value of the ID that we passed past. Of course, because we only pass a value past, so the record will be taken out only one.


How do you modify a recordset when it is removed? In fact, it is the equivalent of inserting the data again.


Open menu Insert-> Live Objects-> record Update Form


Oh! Is it like the record Insert form, it's just a unique key column (the only keyword field) that we've been nagging about for half a day, choosing the ID field, and the next thing is simple, As we learned in the section on adding records, revise to your satisfaction. Defulat value does not care about it, the final result is shown in the figure.





Ok, my nephew plays the lantern-as usual, open the browser to test our results and select the record we just added: DD for editing, as shown in the figure.





Click the Update Record button to jump to the display page, as shown in the figure, our data has been changed, hehe, happy!



OK, after reading this data editing process, I believe that the deletion of the operation will not be a difficult task for you, the next section we will explain how to delete data. You can also take it easy---after all, some of the editorial records are still quite confusing:)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.