I have a datagrid which is editable and I need to send that back to the database via a CFC for insertion into the database after all the editing is complete. Dumping the array collection to cfdump tells me that I have an array with items and a structure but i cannot understand how to "loop" through each and insert into the DB.
There seems to be very little written which actually works! My MXML and CFC are below but give me the error of "You have attempted to dereference a scalar variable of type class coldfusion.runtime.Array as a structure with members." -which is nice
all help is much appreciated - thanks
[Bindable]
private var getconsent:ArrayCollection = new ArrayCollection([
{LocationName:'Service A', Contact: 'Bob Jones' },
{LocationName:'Service B', Contact: 'Jane Smith' },
{LocationName:'Service c', Contact: 'Doug Johnson' },
{LocationName:'Service d', Contact: 'John Jackson'}
]);
public function send():void {
cfdata.sendData(getconsent.source);
}
public function send_Result(event:ResultEvent):void {
Alert.show('ok');
}
public function send_Fault(event:FaultEvent):void {
Alert.show(event.fault.message);
}
]]>
</mx:Script>
<mx:RemoteObject
id="cfdata"
showBusyCursor="true"
destination="ColdFusion"
source="buildtest.test2">
<mx:method name="sendData" result="send_Result(event)" fault="send_Fault(event)" />
</mx:RemoteObject>
<mx:DataGrid id="myGrid"
dataProvider="{getconsent}" editable="true" >
<mx:columns>
<mx:DataGridColumn dataField="LocationName" width="150"
editable="false"/>
<mx:DataGridColumn dataField="Contact" width="150" />
</mx:columns>
</mx:DataGrid>
<mx:Button label="Update DB" click="send()"/>
<cfcomponent displayname="sendData" output="false" >
<cffunction name="sendData" access="remote" output="no" returnType="void" required="yes" >
<cfargument name="getconsent" type="any" required="true">
<cfloop from="1" to="#ArrayLen(getconsent.dataprovider)#" index="i">
<cfquery name="clientconsent" datasource="gvr">
INSERT INTO ClientConsent"
(Location)
VALUES
('#getconsent.dataprovider.LocationName[i]#')
</cfquery>
</cfloop>
</cffunction>
</cfcomponent>
array
1 struct
Contact Bob Jones
LocationName Service A
mx_internal_uid 807D204F-A315-7D78-C745-BAD78087CB28
2 struct
Contact Jane Smith
LocationName Service B
mx_internal_uid EAA43EF4-A7EA-82C9-5F3C-BAD780D7FD6F
3 struct
Contact Doug Johnson
LocationName Service c
mx_internal_uid 9768D6D2-8F97-5F4D-767C-BAD780D7B478