17 Replies Latest reply on Sep 13, 2010 11:41 PM by Daniel Pride

    Flex form to insert data into Database

    dondoiron

      Hey!

      I'm new to Flex and am trying to get a few basic features working.

      I've followed a couple video tutorials on how to create a form and have it insert the data to your database, but for some reason the data never gets written to the DB.

       

      I've followed the following 2 tutorials:

      http://www.youtube.com/watch?v=MGCrRlC4i5E

      http://www.adobe.com/devnet/flex/testdrive/articles/2_modify_the_database.html

       

      Both were quite easy to follow but for some reason when I run the application and enter data nothing gets saved to the database...  Anyone else have this issue or any information that may help in resolving this issue?

       

      Thanks!

        • 1. Re: Flex form to insert data into Database
          nlk10010

          Funny you should say that. I logged onto these forums because I had been following the

          "Build an application in an hour" tutorial (Employees/Departments) and ran into exactly the same hurdle. Everything seems to work fine (I can retrieve my records) but when I go to Add a record and hit Submit NOTHING happens. No error messages, no record in the database, nothing. Now the difference is that I'm trying to use an SQL Server 2008 Express database through ColdFusion. My DSN in the CF Administrator validates fine and Flash remoting is set to on but nothing happens.

           

          I saw a poster with a similar issue in the comments section of one of those tutorials but the response from an Adobe tech was, to put it mildly, inscrutable.

           

          I'm actually comparing/contrasting C# (WebForms/MVC) and FlashBuilder for a web project I'm undertaking and while the Flash interface and coding model seems a bit cleaner/easier the data actually DOES get written in C#.

           

          Good Luck, I'll root around a bit more to see what I come up with on this issue.

          • 2. Re: Flex form to insert data into Database
            SunilAdobe Adobe Employee

            Are you creating the Employee object every time when you want to create a new employee, because if its not done, it might have the value ID as the previous one and it might fail adding the new record to the database (if the id is an auto id)

             

            Thanks

            -Sunil

            • 3. Re: Flex form to insert data into Database
              dondoiron Level 1

              Tried that and still nothing...

              • 4. Re: Flex form to insert data into Database
                dondoiron Level 1

                Thanks for the reply.  Fingers crossed because this is quite frustrating...

                Another thing that should be mentioned is when I update a record through a flex application it updates the data in the flex datagrid but the changes don't get updated in the DB....

                 

                Thanks again,

                Don

                • 5. Re: Flex form to insert data into Database
                  nlk10010 Level 1

                  So I assume you can RETRIEVE the records?

                   

                  What kind of data service? PHP? CF?

                   

                  I am not using the test employee database, I've got a separate table with an Identity int primary key (not nullable, of course), other fields are strings which DO allow nulls, plus a byte array.

                   

                  As suggested, when the "Add" button is click I create a new object; e.g. address = new Address(). I DON'T input the key column. What I notice is that when I click Submit NOTHING happens. It doesn't look like the app is actually calling the service (there is NO error message and apparently NO disk activity). So I don't even think it's TRYING to get to the database.

                   

                  We shall see.

                  • 6. Re: Flex form to insert data into Database
                    dondoiron Level 1

                    I can retrieve the records and plot data in some graphs and data grids.

                    I have a WAMP set up so I'm using MySQL and PHP as my DB and service.

                     

                    Sounds like our issue is similar...  I've even tried putting in a new state so when you click on the add record button it sends you to a new page/state. That works fine, but again the data doesn't get saved.

                     

                    Here's the code for my add event...

                     

                    protected function button3_clickHandler(event:MouseEvent):void

                    {

                    var employee5:Employee = new Employee();

                    employee5.id = parseInt(idTextInput2.text);

                    employee5.first = firstTextInput3.text;

                    employee5.last = lastTextInput3.text;

                     

                    createEmployeeResult3.token = employeeService.createEmployee(employee5);

                     

                    currentState="Done";

                    }

                    • 7. Re: Flex form to insert data into Database
                      SunilAdobe Adobe Employee

                      There are 2 reasons why this could be happening.

                       

                      a. If you have enabled datamanagement for your service, you have to manually do a commit, as it is set to off by default.

                      b. there is an issue with the service call, either its not happening or the server side function has syntactical or SQL errors.

                       

                      Can you enable Network monitor to check whether the request that the application is sending and the response it is getting back are in line with your expectations.

                       

                      Thanks

                      -Sunil

                      • 8. Re: Flex form to insert data into Database
                        SunilAdobe Adobe Employee

                        If your id is auto id, take off the assignment for employee5.id, I think that is the reason why it will fail.

                         

                        Thanks

                        -Sunil

                        • 9. Re: Flex form to insert data into Database
                          dondoiron Level 1

                          I'm assuming that the function is correct since it was generated by Flash Builder 4...   And having some experience with PHP the syntax looks ok.

                           

                          I have a feeling it could be something with the enabled "datamanagement" and the commit...?

                          Do you have instructions or resources on how to either disable datamanagement for the service or how to do the manual commit?

                           

                          Thanks,

                          Don

                           

                          P.S.  I took out the ID assignment and still nothing...

                          • 11. Re: Flex form to insert data into Database
                            nlk10010 Level 1

                            I think Sunil mentioned the same thing as in the comments to the "Flex in an Hour" tutorial: commit(). I was going to ask if this was explained anywhere as it's not mentioned anywhere in the tutorial. However, I see Sunil's last post and I will take a look. If your click of "Submit" is not doing ANYTHING then that might be the issue (as if it was an error you'd see an error message, there's a fault handler in the code).

                            • 12. Re: Flex form to insert data into Database
                              dondoiron Level 1

                              This sounds like it's the issue.

                               

                              Since I'm still learning this and I'm a little un-familiar with the syntax...

                              Where abouts would this go and what needs to be changes in the syntax...

                               

                              For example if this is my create event statement:

                               

                              protected function button3_clickHandler(event:MouseEvent):void

                              {

                              var employee5:Employee = new Employee();

                              //employee5.id = parseInt(idTextInput2.text);

                              employee5.first = firstTextInput3.text;

                              employee5.last = lastTextInput3.text;

                               

                              createEmployeeResult3.token = employeeService.createEmployee(employee5);

                              currentState="Done";

                              }

                               

                              I would now assume that "bookService.getDataManager(bookService.DATA_MANAGER__BOOK).autoCommit = true;" needs to go somewhere in that event and also the syntax needs to be updated...?

                               

                              Thanks again for all your help with this!

                              • 13. Re: Flex form to insert data into Database
                                SunilAdobe Adobe Employee

                                Great, You can set autocommit to true once for the service, not everytime.

                                Can you please file a bug for us to

                                 

                                a. auto generate the autocommit to be set to true

                                b. generate some comments explaining what autocommit does.

                                 

                                Thanks

                                -Sunil

                                • 14. Re: Flex form to insert data into Database
                                  dondoiron Level 1

                                  Based on this create new Employee event can you show me how the syntax would look to set this to autocommit?

                                   

                                  protected function button3_clickHandler(event:MouseEvent):void

                                  {

                                  var employee5:Employee = new Employee();

                                  //employee5.id = parseInt(idTextInput2.text);

                                  employee5.first = firstTextInput3.text;

                                  employee5.last = lastTextInput3.text;

                                   

                                  createEmployeeResult3.token = employeeService.createEmployee(employee5);

                                   

                                  currentState="Done";

                                  }

                                   

                                  Where does this line of code go, "bookService.getDataManager(bookService.DATA_MANAGER__BOOK).autoCommit = true;", and how does the syntax change based on the above snippet?

                                   

                                  Thanks and I'll submit an issue for this.

                                  • 15. Re: Flex form to insert data into Database
                                    SunilAdobe Adobe Employee

                                    The autocommit setting can go in the application's creationcomplete event or you could create a button to toggle this setting in your user interface.

                                     

                                    Thanks

                                    -Sunil

                                    • 16. Re: Flex form to insert data into Database
                                      dondoiron Level 1

                                      Fixed!!

                                       

                                      For those of you who have had this issue...  Here's my code for creating a new employee with the commit()

                                       

                                      protected function button3_clickHandler(event:MouseEvent):void

                                      {

                                      var employee5:Employee = new Employee();

                                      //employee5.id = parseInt(idTextInput2.text);

                                      employee5.first = firstTextInput3.text;

                                      employee5.last = lastTextInput3.text;

                                       

                                      createEmployeeResult3.token = employeeService.createEmployee(employee5);

                                      employeeService.commit();

                                      currentState="Done";

                                      }

                                      • 17. Re: Flex form to insert data into Database
                                        Daniel Pride Level 1

                                        WOW, THANKS

                                        Somebody really blew it in training.

                                        That little omission of an absurdly obvious requirement just caused me three days of pure hell.

                                        EVERYONE uses auto increment on a table if they know what they are doing and it should be  understood that a lot of people need to know about

                                        commitIO

                                        Jesus

                                         

                                        P.S. is there anyway we can all give dondoiron a star for the answer.

                                        He deserves a dozen.

                                         

                                        Dan Pride