Update Record (Cont.) - Page 20
August 21,2002
Just as for the Insert Record behavior, we have to create a
form that reflects the database columns and table we want to update. But I've
been having you do things the long way. Now that you know how to use the individual
server behaviors, instead of creating the form we will use one of Dreamweaver
MX's timesaving Objects – the Record Update
Form.
Select Insert > Application Objects > Record Update Form, and you will be presented
with the following dialog box:
As seen above, select the conn_webprodmx connection, books table
to update, rsUpdateBook recordset,
book_id as the unique key column and redirect to categories3.asp after updating.
Remove the following form fields from the list: book_image_path, category_id, and book_id (you should always remove unique IDs from the Update Record behavior because no one should
ever be allowed to edit these values in normal circumstances. Also, we don't
need to edit the image path through this form). Hit OK and the Update Record form should be created for you
in your document.
Test your page in a browser, and try editing some of your
book records.
We left the category_id out of the update to start off with, as explained above, but we might
want to update this – that is, we might want to place a book into a different
category. Let's do that now. We need to do three things: add the category_id column to the rsUpdateBook recordset, create a new recordset to retrieve the categories, add
a field for the category ID in our update form, and add the category_id column to the Update Record
behavior.
On the edit_book.asp page, get up the details for the rsUpdateBook recordset again, and add the category_id column to the SELECT SQL
statement. Your SQL should now look like this:
SELECT book_id, book_author_fname, book_author_lname, book_isbn, book_price, book_title, page_count, category_id
FROM books
WHERE book_id = MMColParam
We also need to add a form field to
the update form. Before we do that we should think about how we want to display
the categories for display. The only thing stored in the book record that
associates the book record with a particular category is the category_id. Most likely we will not have memorized the ID numbers of our categories
– it would be more practical to retrieve the categories and select which category
we want to place the book in from a listbox field. Thus we need to create
a new recordset and retrieve the categories.
Create a new recordset called rsGetCategories.
Make sure the conn_webprodmx connection is selected, and type the following SQL into the appropriate
field:
SELECT category, category_id
FROM categories
ORDER BY category ASC
Hit OK.
In your form, add a row above the seventh row that contains the Submit
button (there should now be eight rows in all), and type the text "category"
in the left column of this row. Now add a listbox field to the update form
in the right column of this row (use Insert
> Form
Objects > List/Menu).
Update Record - Page 19
Dynamic Dreamweaver MX
Update Record (Cont.) - Page 21
|