我有这个节点msnodesqlv8
连接,我正在计算一个表中的记录数。我得到的结果为{ total: 26 }
,预期结果应为26.这是我的代码:
pool.connect().then(() => {
pool.request().query('SELECT count([TaskID]) as total FROM [db_test].[dbo].[tb_test]', (err, result) => {
myResults = result.recordset[0];
console.log(myResults);
})
});
答案 0 :(得分:1)
当您以对象形式获取数据时。现在你必须从结果中访问该对象。
pool.connect().then(() => {
pool.request().query('SELECT count([TaskID]) as total FROM [db_test].[dbo].[tb_test]', (err, result) => {
myResults = result.recordset[0].total;
console.log(myResults.total); // it should provides you expected result
})
});