Siva Ganesh
Siva Ganesh

Reputation: 45

Not able to fetch 0 row count in action script

I am developing an AIR App using Flashbuilder. Im using Sqlite database. While fetching records from sqlite database, if there is no rows available, instead of showing row count as 0 I am getting an exception "cannot access a property or method of a null object reference"

var sqlsmt:SQLStatement=new SQLStatement();             
var folder:File=File.applicationDirectory;                 
var path:File = folder.resolvePath("mydb.db");
sqlcon.open(path);              
sqlsmt.sqlConnection=sqlconcheck;
sqlsmt.text="select * from mytable";
sqlsmt.execute();
var result:SQLResult = sqlsmt.getResult();
sqlsmt.cancel();
var count:int = result.data.length;

Not able to get rid of this error.Please help me in this. Thanks in advance.

Upvotes: 0

Views: 193

Answers (1)

Pete TNT
Pete TNT

Reputation: 8403

var count:int = result.data != null ? result.data.length : 0; 

Which is just shorthand for

var count:int;

if(result.data != null) {
   count = result.data.length;
} else {
   count = 0;
}

Upvotes: 1

Related Questions