QueryGetRow

Description

This function returns a struct that has all the columns as keys and their corresponding values.

Returns

Struct

Category

Syntax

QueryGetRow(query, rowNum)

History

ColdFusion (2018 release): Introduced named parameters.

Introduced in ColdFusion 11.

Parameters

Parameter

Description

query

The query object to get data from.

rowNum

The position of the row.

Example

<cfscript>
       myQuery=QueryNew("ID,Name,Rating","integer,varchar,double");
       myFirstData=StructNew();
       myFirstData={ID=1,Name="Nixon",Rating=56.87};
       QueryAddRow(myQuery,myFirstData);
       WriteOutput("Recordset updated with struct data:");
       WriteDump(myQuery);
       myGet=QueryGetRow(myQuery,1);
       WriteOutput("Returns struct with columns as keys:");
       WriteDump(myGet);
       //Try to return struct values for row=2 that does not exist
       try{
             QueryGetRow(myQuery,2);
       }
       catch(any q){
             WriteOutput(q.message);// Displays appropriate message
       }
</cfscript>

Output

Using member function

<cfscript>
       myQuery=QueryNew("ID,Name,Rating","integer,varchar,double");
       myFirstData=StructNew();
       myFirstData={ID=1,Name="Nixon",Rating=56.87};
       QueryAddRow(myQuery,myFirstData);
       myRow=myQuery.getRow(1);
       WriteDump(myQuery);
</cfscript>
Adobe logo

Sign in to your account