User Guide

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 tables 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.