[SOLVED] parameter count mismatch sqlite and qt error
-
i have error with sqlite query
i don't know where is the problem the problem exactly
i have make a default connexion in mainwindow.cpp
and i just get the default connexion and query the data base, but isn't works
her is my code so far
@
QSqlDatabase db = QSqlDatabase::database() ;QSqlQuery query ;
query.prepare("select seq from sqlite_sequence where name= ? ");
query.addBindValue("articles");
if(!query.exec())
{
QMessageBox::critical(this,"Inventoria solti",query.lastError().text());
return ;
}while (query.next())
{
ui->lineEdit->setText(query.value(0).toString());
}@ -
Hi,
I think you need to pass your "db" to your QSqlQuery query,
Like this,
@QSqlQuery query(db);@ -
i tried this but i get the same error
i don't know where is the problem every thing is correct , because i use the same code in other example an it works
@
QSqlDatabase db = QSqlDatabase::database() ;QSqlQuery query(db) ; QString queryString = "select seq from sqlite_sequence where name= ?"; query.prepare(queryString); query.addBindValue(str); if(!query.exec()) { QMessageBox::critical(this,tr("Inventaire"),query.lastError().text()); return; } while(query.next()) { ui->articleCodeLineEdit->setText("ART_" + QString::number(query.value(0).toInt() + 1)); return ; } if(ui->articleCodeLineEdit->text().isEmpty()) ui->articleCodeLineEdit->setText("ART_1");
@
-
Hi,
You can alternatively try this,
@
QSqlQuery query(QSqlDatabase::database());
query.exec(select seq from sqlite_sequence where name='"+str+"');
while (query.next()) {
qDebug() << query.value(0).toInt();
}
@ -
i tried your code and i get
"no such table sqlite_sequence enable to execute statement" error
-
Thats strange the following coe works for me,
@
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("/root/test.db");bool ret = db.open();
QSqlQuery query(QSqlDatabase::database());
QString str = "t1";
query.exec("select seq from sqlite_sequence where name='"+str+"'");while (query.next()) {
qDebug() << query.value(0).toString();
}
@ -
sorry, p3c0, for the stupide error
i don't write the path of database correctly
i have writed
this path " E:\apprendreQt\gestionstock6\database\inventaire.db"
instead of "E:/Programing/database/inventaire.db"
int mainwindow.cpp
her is the code of connexion
@ m_db = new QSqlDatabase;
// Base de données traitement
*m_db = QSqlDatabase::addDatabase("QSQLITE") ;
m_db->setHostName("localhost");
m_db->setDatabaseName("E:/Programing/database/inventaire.db");
m_db->setPassword("");
m_db->setUserName("");
if(!m_db->open())
QMessageBox::critical(this,"erreur connecting",m_db->lastError().text());m_fenetreArticle = new article(this); m_fenetreArticle->setWindowFlags(Qt::Window);@