Qt-QSqlite : Not able to fetch the record if only one record is present
Sorry I posted this query again...
My Original query was:
I am trying to fetch the records from the table. I am able to get all the records except the first record.
Same way if there is only one record, then that record is also not fetched.
How could I get the only record present in my table.
I am using Qt, QSqlite and trying to get the records us开发者_运维技巧ing QSqlQuery.next()
function.
Like:
while(query.next())
.............................................................................
I have only 1 record in Database like :UserId = 1 and Name = Naveen. To get this record I tried like:
strQuery = QString("select Name from User_Table where UserID = 1");
if (!ExecuteQuery(strQuery, sqlQuery))
{
qDebug() << sqlQuery.lastError();
return false;
}
while (sqlQuery.next())
{
QString strName = sqlQuery.value(0).toString();
}
This way I didn't get the Name Naveen.I tried to debug, but that while loop never executes –
Any suggestions on this, please... Thanks
Just out of interest, if you change your while loop to
do
{
QString strName = sqlQuery.value(0).toString();
} while (sqlQuery.next());
does it work? If so it means that something already calls QSqlQuery::next() or QSqlQuery::first() before your loop.
精彩评论