2013-05-04 138 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

回答