开发者

How do I pass an edited Flex datagrid to a CFC to insert to a database

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开发者_Go百科-8F97-5F4D-767C-BAD780D7B478 


If you're using CF9, try DCD with Flex 4: http://ria.dzone.com/articles/flash-remoting-and-coldfusion

If you're using CF8 with Flex 3, try LCDS: http://www.adobe.com/devnet/coldfusion/articles/data_app.html


Would it be easier for you to work with a query object instead of an array of structs? I created a UDF to convert an ArrayCollection to a Query [ArrayCollectionToQuery] in CF after it's returned from your Flex application.


Hi Adam thanks for this it looks very useful, however i am not sure how to use it to insert data into my DB

<cfquery name="clientconsent" datasource="gvr">
INSERT INTO dbo.ClientConsent
(Location, ClientAppointments, ClientDemographics)
VALUES(
      #qresult#
)
</cfquery>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜