QSqlQuery不位于有效记录上 [英] QSqlQuery not positioned on a valid record

查看:129
本文介绍了QSqlQuery不位于有效记录上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试选择我的日期库的字段,代码是:

I'm trying select a field of my date base, the code is:

if (db.db().isOpen())
{
  qDebug() << "OK";
  QSqlQuery query("SELECT state FROM jobs WHERE jobId = '553'", db.db());
  qDebug() << query.value(0).toString();
}
else
  qDebug() << "No ok"; 

查询是正确的,因为当我做qDebug()< query.size,return 1。

The query is correct because when i do qDebug() << query.size, return 1.

但是使用qDebug()< query.value(0).toString();返回:

but with qDebug() << query.value(0).toString(); return:

OK 
QSqlQuery::value: not positioned on a valid record
""

如何解决?

非常多。

推荐答案

之前应该调用 query.first()您可以访问返回的数据。此外,如果您的查询返回多行,您应该通过 query.next()进行迭代。

You should call query.first() before you can access returned data. additionally if your query returns more than one row, you should iterate via query.next().

这篇关于QSqlQuery不位于有效记录上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆