vendredi 26 décembre 2014

QT store database record

For testing purposes i'm trying to store a value from my database into a label, with no success. I am reciveing several errors like "QSqlQuery::prepare: no driver QSqlQuery::value: not positioned on a valid record SQL QUERY: "" SQL ERROR: QSqlError("", "Unable to fetch row", "No query")"



QSqlQuery qry1;
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("/Users/Daniel/Dropbox/Stock_Control.sqlite");
if(!db.open())
ui->label->setText("Unable To Connect To Database");
qry1.prepare("SELECT Customer_ID FROM Customer WHERE Customer_ID >1");
qry1.exec();
ui->checkBox->setChecked(true);
ui->lineEdit_Account_ID->setReadOnly(true);
ui->lineEdit_VAT->setReadOnly(true);
ui->comboBox->setCurrentIndex(Searching);
ui->dateEdit_Account_Since->setDate(QDate::currentDate());
ui->label->setText(qry1.value(0).toString());
qDebug() << "SQL QUERY:" << qry1.executedQuery();
qDebug() << "SQL ERROR:" << qry1.lastError();
SetOthersFalse();

Aucun commentaire:

Enregistrer un commentaire