This example uses a coffee inventory model as a theme for the data.
| Fields created in the Beans1 table | |
|---|---|
| Field | Data type |
| Bean_ID | numeric |
| Name | char |
| Price | char |
| Date | date |
| Descript | char |
<HTML>
<HEAD>
<TITLE>DBASE Table Setup</TITLE>
</HEAD>
<BODY>
<!----------------------------------------------------------------
Before running this code, you need to create the
newtable data source in the ColdFusion Administrator,
specifying the Intersolv dBase/FoxPro ODBC driver.
------------------------------------------------------------------>
<!----------------------------------------------------------------
Create a table Beans1 and specify its columns by using the CFQUERY
tag with the SQL CREATE TABLE command.
------------------------------------------------------------------>
<CFQUERY NAME=xs DATASOURCE="newtable">
CREATE TABLE Beans1 (
Bean_ID numeric(6),
Name char(50),
Price char(50),
Date date,</P>
Descript char(254))
</CFQUERY>
<!----------------------------------------------------------------
Insert data into each column of the table Beans1 using the
CFQUERY tag with the SQL INSERT INTO command. This data constitutes
one record.
------------------------------------------------------------------>
<CFQUERY NAME=xs DATASOURCE="newtable">
INSERT INTO Beans1 VALUES (
1,</P>
'Kenya',
'33',
{ts '1999-08-01 00:00:00.000000'},
'Round, rich roast')
</CFQUERY>
<!----------------------------------------------------------------
Create a second record and add it to the Beans1 table using the
CFQUERY tag with the SQL INSERT INTO command.
------------------------------------------------------------------>
<CFQUERY NAME=xs DATASOURCE="newtable">
INSERT INTO Beans1 VALUES (
2, 'Sumatra',
'21',
{ts '1999-08-01 00:00:00.000000'},
'Complex flavor, medium-bodied')
</CFQUERY>
<!----------------------------------------------------------------
Create a third record and add it to the Beans1 table using the
CFQUERY tag with the SQL INSERT INTO command.
------------------------------------------------------------------>
<CFQUERY NAME=xs DATASOURCE="newtable">
INSERT INTO Beans1 VALUES (
3, 'Colombia',
'89',
{ts '1999-08-01 00:00:00.000000'},
'Deep rich, high-altitude flavor')
</CFQUERY>
<!----------------------------------------------------------------
Create a fourth record and add it to the Beans1 table using the
CFQUERY tag with the SQL INSERT INTO command.
------------------------------------------------------------------>
<CFQUERY NAME=xs DATASOURCE="newtable">
INSERT INTO Beans1 VALUES (
4,</P>
'Guatamala',
'15',
{ts '1999-08-01 00:00:00.000000'},
'Organically grown')
</CFQUERY>
<!----------------------------------------------------------------
Replace each manually inserted Bean_ID value with a new unique
index value.
------------------------------------------------------------------>
<CFQUERY NAME=xs DATASOURCE="newtable">
CREATE UNIQUE INDEX Bean_ID on Beans1 (Bean_ID)
</CFQUERY>
<!----------------------------------------------------------------
Get all records from Beans1 and store them in the query object
QueryTest2 using the CFQUERY tag.
------------------------------------------------------------------>
<CFQUERY NAME=""QueryTest2"" DATASOURCE="newtable">
SELECT * FROM Beans1
</CFQUERY>
<!----------------------------------------------------------------
Display the Bean_ID and Name for each record in the query object
QueryTest2.
------------------------------------------------------------------>
<CFOUTPUT QUERY=""QueryTest2"">
#Bean_ID# #Name#<br>
</CFOUTPUT>
</BODY>
</HTML>