1 Reply Latest reply on Jul 9, 2009 10:35 AM by cputnam14

    SQLResult record count and no results returned question

    cputnam14

      Hey all,

      So the probelm I am having is this. I have a local db created by air. I am running a select statement based on what the user types in a text box. Everything works just fine as long as there is a record in the database that matches what the user types in. However, if the select query returns no records I start getting an error. So here is my results function.

       

      private function SearchRes(event:SQLEvent):void
              {
                  var result:SQLResult = sqlstat.getResult();

                  trace(result.data);
                  var numResults:int = result.data.length;

       

                if(numResults == 1)
                  {
                      Alert.show("You got results", "Epic Win");
                  } else {
                      Alert.show("You have no results", "Epic Fail");
                  }

       

      }

       

      Now if the user searches for something that is in the database, my trace(result.data) displayes [object Object] and everything works. If they don't find anything my trace(result.data) displays null and I get an error when I do var numResults:int = result.data.length; because obviously data doesn't exist.

       

      So my question is how can I handle this. In coldfusion I would do a queryname.recordcount and it will return from 0 to whatever. Is there something similar with air that I don't know about?

       

      Any help will be recipricated with a happy dance right here in my office.

        • 1. Re: SQLResult record count and no results returned question
          cputnam14 Level 1

          and 5 seconds later I figured it out.

           

          private function SearchRes(event:SQLEvent):void
                  {
                      var result:SQLResult = sqlstat.getResult();

                      trace(result.data);

                   if(result.data == null){
                      var numResults:int = 0;
                         }else{

                      var numResults:int = result.data.length;

                     }

           

                    if(numResults == 1)
                      {
                          Alert.show("You got results", "Epic Win");
                      } else {
                          Alert.show("You have no results", "Epic Fail");
                      }

           

          }