3 Replies Latest reply on Sep 26, 2008 6:40 AM by Newsgroup_User

    Data Handling. please help.

    masita18
      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:
      <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
      <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:
      <!-- 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:
      <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?
        • 1. Re: Data Handling.
          Level 7

          "masita18" <webforumsuser@macromedia.com> wrote in message
          news:gbfj71$98u$1@forums.macromedia.com...
          > Is it possible that I get a whole data in a table from a database using
          > RemotObject(.cfc)?
          > Eg.:
          > Table name: Name
          > Data Inside: Alex, Mary, John, Dick, Harry
          >
          > So far, I am only able to retrieve a data. I'm not able to retrieve the
          > rest
          > of the names in the table.
          > Eg.: Alex
          >
          > I tried using a HTTPService:
          > <!-- Setup the connection to the Coldfusion CFM - Data.cfm -->
          > <mx:HTTPService id="dataRequest" resultFormat="e4x"
          > url=" http://localhost:8500/Wimeals/src/Database/Data.cfm">
          > </mx:HTTPService>
          >
          > And set the dataprovider of my comboBox as:
          > <mx:ComboBox id="cBoxObject" dataProvider="{dataRequest.lastResult.pos}"
          > />
          >
          > But the problem with this is that i only get to retrieve the data when the
          > HTTPService was first executed. I tried adding a data in the application
          > itself
          > and the data that i just add is not shown in the comboBox.
          > First executed: Alex, Mary, John, Dick, Harry
          > After adding a name Kingston as a new user the comboBox shows:
          > Alex, Mary, John, Dick, Harry (Kingston is missing!)
          >
          > Is there any way that i could solve this problem. Please help me.

          You need to either call the service again, or shove the value of lastResult
          into a variable and edit that when you add a new user.


          • 2. Re: Data Handling.
            masita18 Level 1
            How do I actually call the sevice again? Or shove the value of lastResult into a variable and edit that when I add a new user? I'm not sure how to do it? Can u give me a sample code?

            Because i tried to use "dataRequest.send()" everytime when i want to retrive the set of records but it keep giving me the old records without the new added user.
            • 3. Re: Data Handling.
              Level 7

              "masita18" <webforumsuser@macromedia.com> wrote in message
              news:gbhlmq$s55$1@forums.macromedia.com...
              > How do I actually call the sevice again? Or shove the value of lastResult
              > into
              > a variable and edit that when I add a new user? I'm not sure how to do it?
              > Can
              > u give me a sample code?
              >
              > Because i tried to use "dataRequest.send()" everytime when i want to
              > retrive
              > the set of records but it keep giving me the old records without the new
              > added
              > user.

              That sounds like you did call the service again, and you've run up against a
              Q7:
              http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf

              To shove the value of lastResult into a variable do something like this.


              [Bindable]
              private var myXMLListCollection:XMLListCollection = new XMLListCollection()

              private function handleServiceResult(e:ResultEvent){
              myXMLListCollection.source=e.result;
              }

              Set that as the result handler for your service, and set the
              XMLListCollection as your dataProvider.

              HTH;

              Amy