10 Replies Latest reply on May 12, 2009 6:48 AM by chandler124

    Script to put Datas from Database to TextInput

    chandler124

      Hello,

       

      As it is said in the title, I would like to put Datas from Database to Textinput. Here's my application :

       

      Cliché 2009-05-12 11-55-40.tiff

      Well, what I want to do is when you click on the lines in the Datagrid, the "Nom Area" is completed by the Name in the Datagrid, the "adresse area" by the adress in the Datagrid ...

       

      Can someone help me ? please

       

      Thank you

        • 1. Re: Script to put Datas from Database to TextInput
          Michael Borbor Level 4

          What you need is to use the DG property selectedItem for instance this is an example where your DG is named myDG and you have a property in your dataProvider named Group.

           

          <mx:Text text="{myDG.selectedItem.Group}" />
          
          1 person found this helpful
          • 2. Re: Script to put Datas from Database to TextInput
            chandler124 Level 1

            Thank you but in text="{myDG.selectedItem.Group}" myDG means for example "Nom" so I'm trying to do text="{Nom.selectedItem.Group}" but there's an error which is : Acces to property Nom undefined. Any help ?

             

            Thank you

            • 3. Re: Script to put Datas from Database to TextInput
              Michael Borbor Level 4

              Check the names of the dataProvider, how do you define that column in your dataGrid?

              • 4. Re: Script to put Datas from Database to TextInput
                chandler124 Level 1

                Here's my code

                 

                <code>

                <?xml version="1.0" encoding="utf-8"?>

                <mx:Application

                xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:fourD="http://www.4d.com/2007/mxml" layout="absolute"  viewSourceURL="srcview/index.html" backgroundGradientAlphas="[1.0,1.0]" backgroundGradientColors="[#EDE3E3, #555555]" color="#040404" height="899">

                 

                <mx:Script>

                <![CDATA[

                import fourD.sql.*;

                import mx.controls.Alert;

                import mx.rpc.events.FaultEvent;

                import mx.rpc.events.ResultEvent;

                 

                [Bindable]

                private var _resultSet:SQLResultSet;

                 

                // Initialisation de la connection

                private function connectHandler(event:Event):void

                {

                 

                fourDSQLService.execute("SELECT * FROM clients"); }

                 

                 

                private function resultHandler(event:ResultEvent):void

                {

                 

                if(event.result != null) { _resultSet = event.result as SQLResultSet; } }

                 

                // En cas d'erreur

                private function faultHandler(event:FaultEvent):void

                {

                var zeError:String= "Error #" + event.fault.faultCode;

                // Message d'erreur

                Alert.show(event.fault.faultString,zeError); }

                 

                ]]>

                </mx:Script>

                 

                <!-- Declaration du serveur SQL-->

                <!-- Connection automatique au dŽmarrage de l'application (login/mdp)-->

                <!-- ImplŽmentation des fonctions -->

                <fourD:SQLService id = "fourDSQLService"

                host = "127.0.0.1"

                userName = "sqlUser"

                userPassword="sql"

                autoConnect="true"

                result = "resultHandler(event)"

                fault = "faultHandler(event)"

                connect="connectHandler(event)"

                />

                 

                <!-- Declare the 4D datagrid; It is also possible to use Flex embed datagrid -->

                <!-- Bind datagrid source to SQLresultSet coming from 4D-->

                <fourD:DataGrid id="contacts_dg"

                dataProvider="{_resultSet}" x="10" y="207" width="737" height="397"

                />

                 

                 

                <mx:Button x="588" y="627" label="Ajouter" id="btnAjouter"/>

                <mx:Button x="666" y="627" label="Supprimer" id="btnSupprimer"/>

                <mx:Text x="10" y="10" text="Nom" />

                <mx:Text x="10" y="36" text="Secteur d'activitŽ&#xd;"/>

                <mx:Text x="10" y="62" text="Groupe"/>

                <mx:Text x="10" y="112" text="Responsable commercial"/>

                <mx:Text x="10" y="88" text="Adresse"/>

                <mx:Text x="416" y="88" text="Ville"/>

                <mx:Text x="595" y="88" text="Code Postal"/>

                <mx:Text x="10" y="138" text="Responsable production&#xd;"/>

                <mx:Text x="416" y="112" text="Responsable 3"/>

                <mx:Text x="416" y="138" text="Responsable 4"/>

                <mx:Text x="624" y="10" text="Code"/>

                <mx:RadioButton x="610" y="34" label="Client"/>

                <mx:RadioButton x="675" y="34" label="Prospect"/>

                <mx:TextInput x="48" y="8" width="568" id="nomArea" />

                <mx:TextInput x="117" y="34" width="485"/>

                <mx:TextInput x="666" y="8" width="81"/>

                <mx:TextInput x="675" y="86" width="72"/>

                <mx:TextInput x="63" y="60" width="684"/>

                <mx:ComboBox x="157" y="110" width="251"></mx:ComboBox>

                <mx:ComboBox x="157" y="140" width="251"></mx:ComboBox>

                <mx:ComboBox x="512" y="110" width="235"></mx:ComboBox>

                <mx:ComboBox x="512" y="140" width="235"></mx:ComboBox>

                <mx:Text x="317.5" y="161" text="Liste Clients" fontSize="19"/>

                <mx:TextInput x="63" y="86" width="345"/>

                <mx:TextInput x="452" y="86" width="135"/>

                </mx:Application>

                </code>

                • 5. Re: Script to put Datas from Database to TextInput
                  Michael Borbor Level 4

                  This is a minimal example:

                   

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
                       <mx:Script>
                            <![CDATA[
                                 import mx.collections.ArrayCollection;
                  
                                 [Bindable]
                                 public var expenses:ArrayCollection = new ArrayCollection([
                                      {Month:"Jan", Profit:2000, Expenses:120, Amount:45},
                                      {Month:"Feb", Profit:1000, Expenses:200, Amount:60},
                                      {Month:"Mar", Profit:1500, Expenses:500, Amount:30}
                                      ]);
                  
                  
                            ]]>
                       </mx:Script>
                  
                       <mx:TextInput text="{myDG.selectedItem.Expenses}" />
                  
                       <mx:DataGrid id="myDG" dataProvider="{expenses}" />
                  </mx:Application>
                  
                  • 7. Re: Script to put Datas from Database to TextInput
                    Michael Borbor Level 4

                    You're welcome.

                     

                    And this was my post 1000, Yahoo I'm going for the next 1000 posts.

                    • 8. Re: Script to put Datas from Database to TextInput
                      chandler124 Level 1

                      Congratulations Michael

                       

                      And now I would to complete a form with Nom, Adresse ... and put it in the Database. How can I proceed ?

                      • 9. Re: Script to put Datas from Database to TextInput
                        Michael Borbor Level 4

                        Probably before saving the data you should validate it, using the custom validators and once it's validated. You just need to create a function, an Insert statement and send it to your SQLite DB.

                        1 person found this helpful
                        • 10. Re: Script to put Datas from Database to TextInput
                          chandler124 Level 1

                          Well I made a "OK" button in order to validate the form. I understand that I have to associate a function to the property "click" but I don't know how to write the functions. I'm sorry I begin with ActionScript ... :s