Assuming my table has a field called Name with two record called David and Alan. I can insert 1 record called Alex using .cfc approach.
.cfc Approach
Code:
<cffunction name="oCreate" access="public" output="false" returntype="void">
<cfargument name="aObjectTest" type="ModelDb" required="true" />
<!--- var scope everything! --->
<cfset var insertObject = "" />
<cfset var getObjectID = "" />
<cftry>
<cftransaction action="begin">
<cfquery name="insertObject" datasource="#variables.dsn#">
INSERT INTO Objects ( Name)
VALUES (
<cfqueryparam cfsqltype="cf_sql_varchar" value="#aObjectTest.getName()#" maxlength="40" null="no">
</cfquery>
<cfquery name="getObjectID" datasource="#variables.dsn#">
SELECT @@identity as newObjectID
</cfquery>
<cfscript>
aObjectTest.setObjectID(getObjectID.newObjectID) ;
</cfscript>
<cftransaction action="commit" />
</cftransaction>
<cfcatch type="database">
<cftransaction action="rollback" />
<cfthrow type="ModelDb.oCreate" message="#cfcatch.detail#" />
</cfcatch>
</cftry>
</cffunction>
I want to retrieve back all the records to display it in a comboBox using a .cfc aproach.
Currently i can only see the 2 records in the combobox, David and Alan using .cfm approach. I could not see Alex. Not sure if the table is refresh.
.cfm Approach to retrieve all the records
Code:
<cfprocessingdirective suppresswhitespace="yes" pageencoding="utf-8">
<cfquery name="getObjToVar" datasource="testdb3">
SELECT Name FROM Objects
</cfquery>
<cfxml variable="dataXML">
<posters>
<cfloop query="getObjToVar">
<pos>
<cfoutput>#Name#</cfoutput>
</pos>
</cfloop>
</posters>
</cfxml>
<cfoutput>#dataXML#</cfoutput>
</cfprocessingdirective>
HTTPService in .mxml application
Code:
<!-- Setup the connection to the Coldfusion CFM - Data.cfm -->
<mx:HTTPService id="dataRequest" resultFormat="e4x" method="POST"
url="http://localhost:8500/Wimeals/src/Database/Data.cfm">
</mx:HTTPService>
ComboBox code
Code:
<mx:ComboBox id="cBoxObject" dataProvider="{dataRequest.lastResult.pos}" change="{getImagePath()}" / >
Does .cfc allow us to retrieve a set of records inclusive of the latest inserted records?