QSqlQuery read row id (SOLVED)
hello,
i'm implementing a routine that reads row data from SQLITE db.
I want to read id and the other fields.
I can get other fields data correctly, but id data is null.
my code is:
Code:
QSqlQuery query
("SELECT id,name FROM person");
while (query.next())
{
qDebug(query.value(0).toString().toAscii());
qDebug(query.value(1).toString().toAscii());
}
and result is:
Code:
<-- nothing
Tom <-- first row name column value.
Can anybody help me?
Re: QSqlQuery read row id
try
Code:
int id;
id=query.record().value("id").toInt();
use #include <QSqlRecord>
Re: QSqlQuery read row id
I've solved the problem!
problem was creating table, auto increment wasn't set to id field.
Code:
query.exec("create table person(id INTEGER PRIMARY KEY AUTOINCREMENT,namevarchar(20))");
Thanks!
Re: QSqlQuery read row id
Without auto increment you can create table .