2013-05-04 99 views
-1

我怎样才能从表和行指定的记录? 例子:从SQLite获取记录?

这里是DATEBASE(源码)的伪结构:

Row1 Row2 Row3 
Line1 Line1 Line1 
Line2 Line2 Line2 
... ... ... 

我想要使用Qt的通过将DATEBASE取得一行记录。 例如,我怎样才能得到Row2->2号线字符串?

我尝试这样做:

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 ::值:不定位在有效记录”

+0

的DUP http://stackoverflow.com/questions/9000123/qsqlquery-not-positioned-on-a-valid-record – lpapp 2013-10-27 01:36:08

回答