【发布时间】:2013-05-04 12:11:29
【问题描述】:
如何从表和行中获取指定记录? 示例:
这是数据库(sqlite)的伪结构:
Row1 Row2 Row3
Line1 Line1 Line1
Line2 Line2 Line2
... ... ...
我想通过 Qt 从数据库中获取行记录。 例如如何获取 Row2->Line2 字符串?
我试过了:
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("db.db"); //Yes the name of datebase is db.db
if (db.open())
{
QSqlQuery soruAl("SELECT question FROM questions",db);
soruAl.exec();soruAl.first(); //These line does not affect result "QSqlQuery::value: not positioned on a valid record".
qDebug() << soruAl.value(5).toString(); // Here I want to get the 5. line of the question row which is in questions table.
}
else
{
qDebug() << "Error";
}
但我从调试器得到的唯一响应是“QSqlQuery::value: not located on a valid record”
【问题讨论】: