【问题标题】:Getting a record from SQLite?从 SQLite 获取记录?
【发布时间】: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”

【问题讨论】:

标签: c++ sqlite qt


【解决方案1】:

你做错了。这里是the example of doing it right

我还建议您仔细阅读QtSqlQuery help - 那里都有描述。极大的帮助是使用 Qt 的最大优势之一。

【讨论】:

    猜你喜欢
    • 2012-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-11
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多