0 Replies Latest reply: May 5, 2012 7:14 PM by William Spence RSS

    Help uploading data to database using a service

    William Spence Community Member

      I had Flex automatically create me a service to access a database I have on the web to do simple things like populate dropdownlists and it has been working great.  When you have Flex create a service, Flex automatically creates several PHP functions to do things like get all data in a table, to get all data by ID, to delete a record, to create a record, or to update a record.  So far, I have only been using functions that download data to ingest in Flex.  Now, I need to write data to the database and have run into a problem.  I don't know how to organize the data to upload to the database.


      First, I tried creating an arraycollection as the parameter sent to the createProject PHP function, which is a function in the Project Service that writes a record to the project table:


      var projectCollection:ArrayCollection = new ArrayCollection();
      projectCollection.addItem({projNum: 1, custNum, 2, firstName: "John", lastName: "Doe"});




      This did not work, so I tried the same thing but put all the data in an object:


      var projectCollection:Object = {projNum: 1, custNum, 2, firstName: "John", lastName: "Doe"};




      Unfortunately, this did not work either.  In both cases, Flex is saying that I am trying to  coerce a value of type mx.collections:ArrayCollection to an unrelated type valueObjects:Project.  Looking at this, it become apparent that when Flex creates a service, it creates valueObjects, and that I need to be sending a value object.  Sadly, I am not real familiar with valueObjects and do not know how to assign my tables values to the generated valueObjects.


      Could someone please give me a heads up on how to organize my data into an appropriate valueObject to send data to my database?