我使用以下代码来获取emp表中的记录数,代码如下:
var myDb = initDB();
myDb.transaction(function(trans) {
var query = "SELECT COUNT(*) AS c from emp";
trans.executeSql(query, [], function(trans, res) {
var count = res.rows[0].c;
console.log("--- After Count ---"+count);
}, errorHandler); });
The query is giving error : Uncaught TypeError: Cannot read property 'c' of undefined.
How to solve this issue?
Appreciate any help.
html5.webdb.Count=function() {
var db = html5.webdb.db;
db.transaction(function (tx) {
tx.executeSql('SELECT COUNT(*) AS c FROM yourtable', [], function (tx, r) {
console.log( r.rows.item(0).c);
}, function (tx, e) {
alert ("unknown: " + e.message);
});
});
}
感谢James
,我在数据库中使用了它我在下面的代码中描述了它将始终有效以及访问Count(*)的正确方式
select COUNT(*) totalCount from tableName
因此您可以通过访问totalCount 来访问退货计数
console.log(r.rows.item(0).totalCount);