Contents > CFML Reference > ColdFusion Java CFX Reference > Response interface > addQuery PreviousNext

addQuery

Adds a query to the calling template. The query can be accessed by CFML tags in the template. After calling addQuery, the query is empty (it has 0 rows). To populate the query with data, call the Query member functions addRow and setData.

Returns the Query that was added to the template.

Response interface

public Query addQuery(String name, String[] columns)

IllegalArgumentException If the name parameter is not a valid CFML variable name.

addRow, setData

Parameter

Description

name

The name of the query to add to the template

columns

The column names to use in the query

The following example adds a query named People to the calling template. The query has two columns (FirstName and LastName) and two rows:

// Create string array with column names (also track columns indexes)
String[] columns = { "FirstName", "LastName" } ;
int iFirstName = 1, iLastName = 2 ;

// Create a query which contains these columns
Query query = response.addQuery( "People", columns ) ;

// Add data to the query
int iRow = query.addRow() ;
query.setData( iRow, iFirstName, "John" ) ;
query.setData( iRow, iLastName, "Smith" ) ;
iRow = query.addRow() ;
query.setData( iRow, iFirstName, "Jane" ) ;
query.setData( iRow, iLastName, "Doe" ) ; 

Contents > CFML Reference > ColdFusion Java CFX Reference > Response interface > addQuery PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.