7 Replies Latest reply on Oct 6, 2010 12:05 PM by DominikaS

    Upload data to database

    DominikaS

       

      Hi all,

       

      I have a problem with my application. I have created example application on which i can show you my problem. I want my application to download data from database to data grid – that ´s ok. But when i want to upload some data to database from data grid, it doesn´t work – when I click to update button, connecting to database doesn´t start. I am using Wamp Server 2 to communicate with database.

       

      I think that there isn’t problem in my source code (I have checked so many examples). I think there is a problem with Zend Framework – I will try to explain this problem.

       

      I found that application doesn’t upload data to database when folder structure is – look at picture. There is automatically created service in service folder- in my case Tabulka1Service) . But what is confusing is that application downloads data from database without any problems:

      Capture1.PNG

       

      Application only upload data to database when I move all items to service folder – look at picture. After that when I click button it starts to connect to database and uploads data correctly.

       

      Capture.PNG

       

      Why I ask you to help me with this problem?

       

      Because I think it is very bad practice to move items to service folder every time i have created new service - I must totally reconfigure whole service after that– and its waste of time I think.

       

      I would be glad for every help.

       

      Thanks

        • 1. Re: Upload data to database
          camfieldaj Level 1

          It seems that Flex doesn't have the same approach of connecting to databases as some other

          development platforms. What works best for me in my environment is that I use HTTPService calls

          to PHP scripts that I've written to pull data from the database and similar calls to similar scripts

          to do updates and inserts. From reading these forums it seems that this concept is kind of hard

          for some people to grasp. Maybe it was easier for me because I already had experience in PHP

          and Perl, etc.

           

          I've read that Flex 4 or FlashBuilder has much better data discovery tools built into it. I look

          forward to checking them out, but for now the version 3 method works very well for me.

           

          Hope this helps.

          1 person found this helpful
          • 2. Re: Upload data to database
            Devtron Level 3

            Hmmm, I have no problem updating my database through HTTPService objects.

             

            You must have WebServices built for Update/Insert/Delete, etc.

             

            You invoke those and pass parameters to them, via HTTPService object parameters.

             

            I see you are probably not using WebServices, but is that a possibility for you?

            1 person found this helpful
            • 3. Re: Upload data to database
              DominikaS Level 1

              Here is my source code - I am not using HTTP service for connecting to database but i am using php. Here is the source code:

               

              <?xml version="1.0" encoding="utf-8"?>
              <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                             xmlns:s="library://ns.adobe.com/flex/spark"
                             xmlns:mx="library://ns.adobe.com/flex/mx"
                             xmlns:tabulka1service="services.tabulka1service.*"
                             xmlns:valueObjects="valueObjects.*"
                             minWidth="955" minHeight="600"  xmlns:tabulka1service1="services.tabulka1service1.*">
                 
                  <fx:Script>
                      <![CDATA[
                          import mx.controls.Alert;
                          import mx.events.FlexEvent;
                         
                          protected function dataGrid_creationCompleteHandler(event:FlexEvent):void
                          {
                              getAllTabulka1Result.token = tabulka1Service1.getAllTabulka1();
                          }
                                     
                          protected function button_clickHandler(event:MouseEvent):void
                          {
                              // Please uncomment the below line if Data Management is enabled for Tabulka1 and updateTabulka1 is used as the create function.
                              // var tabulka1:Tabulka1 = new Tabulka1();
                              tabulka1.ID = parseInt(iDTextInput.text);
                              tabulka1.Jmeno = jmenoTextInput.text;
                              tabulka1.Prijmeni = prijmeniTextInput.text;
                             
                              updateTabulka1Result.token = tabulka1Service1.updateTabulka1(tabulka1);
                          }
                         
                      ]]>
                  </fx:Script>
                 
                  <!-- Declarations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
                  <fx:Declarations>
                      <s:CallResponder id="getAllTabulka1Result"/>
                      <tabulka1service1:Tabulka1Service1 id="tabulka1Service1" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
                      <valueObjects:Tabulka1 id="tabulka1"/>
                      <s:CallResponder id="updateTabulka1Result"/>
                  </fx:Declarations>
                 
                  <mx:DataGrid x="144" y="26" id="dataGrid" creationComplete="dataGrid_creationCompleteHandler(event)" dataProvider="{getAllTabulka1Result.lastResult}">
                      <mx:columns>
                          <mx:DataGridColumn headerText="ID" dataField="ID"/>
                          <mx:DataGridColumn headerText="Jmeno" dataField="Jmeno"/>
                          <mx:DataGridColumn headerText="Prijmeni" dataField="Prijmeni"/>
                      </mx:columns>
                  </mx:DataGrid>
                  <mx:Form defaultButton="{button}" x="197" y="203">
                      <mx:FormItem label="ID">
                          <s:TextInput id="iDTextInput" text="{tabulka1.ID}"/>
                      </mx:FormItem>
                      <mx:FormItem label="Jmeno">
                          <s:TextInput id="jmenoTextInput" text="{tabulka1.Jmeno}"/>
                      </mx:FormItem>
                      <mx:FormItem label="Prijmeni">
                          <s:TextInput id="prijmeniTextInput" text="{tabulka1.Prijmeni}"/>
                      </mx:FormItem>
                      <s:Button label="UpdateTabulka1" id="button" click="button_clickHandler(event)"/>
                  </mx:Form>
                 
              </s:Application>

               

              I still dont know why update operation doesnt work. Any idea?

              • 4. Re: Upload data to database
                ArrowUpRight Level 2

                Hi Dominika,

                I have had the same issue im my practice.

                Looking to your code, can anly advise you edit you clickHandler function as such:

                 

                 

                protected function button_clickHandler(event:MouseEvent):void {
                     tabulka1 = dataGrid.selectedItem;
                     tabulka1.Jmeno = jmenoTextInput.text;
                     tabulka1.Prijmeni = prijmeniTextInput.text;
                     updateTabulka1Result.token = tabulka1Service1.updateTabulka1(tabulka1);
                }

                 

                I mean, not to assign the primery key ID property of valueObject, but just edit the existing valueObject by picking it up from dataGrid.

                 

                And, i don't know why, but not everything works correctly to me when give the primary key field of database the name of ID, i usually use IDtab, f.e.

                 

                And, at last, I usually don't assign the primary key in phpMyAdmin, i live all fields unmarked, but mark the Key when creating php service with flex's wizard (when you click connect to database, the combobox with fields names appears to cjeck the primary Key)

                 

                Am i clear?

                • 5. Re: Upload data to database
                  DominikaS Level 1

                  I tryed your advice and add:

                   

                  tabulka1 = dataGrid.selectedItem; 

                   

                  This gives me an error:

                   

                  1118: Implicit coercion of a value with static type Object to a possibly unrelated type valueObjects: Osoba. 

                   

                  Did you have the same problem?

                  • 6. Re: Upload data to database
                    ArrowUpRight Level 2

                    Try

                    tabulka1 = dataGrid.selectedItem as valueObjects:Osoba

                     

                    But, u declare

                     

                    <valueObjects:Tabulka1 id="tabulka1"/>

                     

                    does your dataGrid consists of croud of valueObject:Tabuka1 or valueObject:Osoba ?

                     

                    These are different objects so you can't equal them.

                     

                    There is good tutorial on youtube, just watch

                    http://www.youtube.com/view_play_list?p=D7BB0C9BF6C87881&playnext=1&v=x-Da1SD1Ykk

                    • 7. Re: Upload data to database
                      DominikaS Level 1

                      Great, this video helped me.

                       

                      I forgot to add commit: tabulka1Service.commit(); - now i can send updated data to my sql database.

                       

                      Thank you very much, again:)