![MACROMEDIA COLDFUSION 5-DEVELOPING Develop Manual Download Page 179](http://html1.mh-extra.com/html/macromedia/coldfusion-5-developing/coldfusion-5-developing_develop-manual_3293641179.webp)
Creating an Updateable Grid
159
Reviewing the code
The following table describes the code and its function:
Updating the database with cfgridupdate
The
cfgridupdate
tag provides a simple mechanism for updating the database,
including inserting and deleting records. It can add, update, and delete records
simultaneously. It is particularly convenient because it automatically handles
collecting the
cfgrid
changes from the various form variables and generates
appropriate SQL statements to update your data source.
In most cases, you should use
cfgridupdate
to update your database. However, this
tag does not provide the complete SQL control that
cfquery
provides. In particular:
•
It can update only a single table.
•
You have no control over the order of changes. Rows are deleted first, then rows
are inserted, then any changes are made to existing rows.
•
Updating stops when an error occurs. It is possible that some database changes
are made, but the tag does not provide any information on them.
Code
Description
<cfgrid name="employee_grid"
height=300
width=250
vspace=10
selectmode="edit"
query="empdata"
insert="Yes"
delete="Yes">
Populate a
cfgrid
control with data from the
empdata query. Selecting a grid cell enables you
to edit it. Rows can be inserted and deleted. The
grid is 300 X 250 pixels and has 10 pixels of
space above and below it.
<cfgridcolumn name="Emp_ID"
header="Emp ID"
width=50
headeralign="center"
headerbold="Yes"
select="No">
Create a 50-pixel wide column for the data in the
Emp_ID column of the data source. Center a
header named Emp ID and make it bold.
Do not allow users to select fields in this column
for editing. Since this field is the table’s primary
key, users should not be able to change it for
existing records and the DBMS should generate
this field as an automincrement value.
<cfgridcolumn name="LastName"
header="Last Name"
width=100
headeralign="center"
headerbold="Yes">
Create a 100-pixel wide column for the data in
the LastName column of the data source. Center
a header named Last Name and make it bold.
<cfgridcolumn name="Dept_ID"
header="Dept"
width=35
headeralign="center"
headerbold="Yes">
Create a 35-pixel wide column for the data in the
Dept_ID column of the data source. Center a
header named Dept and make it bold.
Summary of Contents for COLDFUSION 5-DEVELOPING
Page 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Page 58: ...38 Chapter 3 Querying a Database ...
Page 134: ...114 Chapter 7 Updating Your Database ...
Page 210: ...190 Chapter 10 Reusing Code ...
Page 232: ...212 Chapter 11 Preventing and Handling Errors ...
Page 238: ...218 Chapter 12 Using the Application Framework ...
Page 262: ...242 Chapter 12 Using the Application Framework ...
Page 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Page 320: ...300 Chapter 15 Indexing and Searching Data ...
Page 336: ...316 Chapter 16 Sending and Receiving E mail ...
Page 374: ...354 Chapter 18 Interacting with Remote Servers ...