Whatever message this page gives is out now! Go check it out!

QuerySetCell

Last update:
May 18, 2026

Description

Sets a cell to a value. If no row number is specified, the cell on the last row is set.

Returns

True, if successful; False, otherwise.

Category

Function syntax

QuerySetCell(query, column_name, value [, row_number ])

See also

QueryAddColumn QueryAddRow QueryNewCreating a recordset with the QueryNew() function in  About recordsets  in the Developing ColdFusion Applications

History

ColdFusion MX 7: Changed the behavior of the function so that it does type validation.

Parameters

ParameterDescription
query
Name of an executed query.
column_name
Name of a column in the query.
value
Value to set in the cell.
row_number
Row number. The default value is last row.

Example

<cfscript>
       myQuery=QueryNew("ID,Name,Value","integer,varchar,integer");
       // Display an empty recordset
       WriteOutput("Empty query object:");
       WriteDump(myQuery);
       // Create a struct for row values
       myStruct=StructNew();
       myStruct={ID=001,Name="George",Value=100};
       // Create an empty struct for values in row 2
       myStruct2=StructNew();
       myStruct2={};
       // Add values for row 1
       QueryAddRow(myQuery,myStruct);
       WriteOutput("Recordset with row 1 and empty row 2:");
       // Add values for row 2
       QueryAddRow(myQuery,myStruct2);
       // Result with one row with values and second row empty
       WriteDump(myQuery);
       // Set cell value for row 2
       QuerySetCell(myQuery,"ID","002",2);
       QuerySetCell(myQuery,"Name","John",2);
       // Display complete recordset with row 1 and 2 populated
       WriteOutput("Recordset with cell values set in rows 1 and 2:");
       WriteDump(myQuery);
</cfscript>
Output
Figure: querysetcell output
querysetcell output

Using member function

<cfscript>
       myQuery=QueryNew("ID,Name,Value","integer,varchar,integer");
       myStruct=StructNew();
       myStruct={ID=001,Name="George",Value=100};
       QueryAddRow(myQuery,myStruct);
       myStruct2={};
       QueryAddRow(myQuery,myStruct2);
       myQuery.setCell("ID","002",2);
       myQuery.setCell("Name","Peter",2);
       myQuery.setCell("Value","200",2);
       WriteDump(myQuery);
</cfscript>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page