[SOLVED] Qt and sqlite problem
-
Hi every body
i'm using QSQLITE as DBMS
so, every thing works fine, until now , i got an error "Driver not loaded"
i'm using the same Database and it works with this code ( driver loaded perfectly )
@ m_db = new QSqlDatabase;
//**base de donnée traitement//*m_db = QSqlDatabase::addDatabase("QSQLITE") ; m_db->setHostName("localhost"); m_db->setDatabaseName("gestionstockDB.db"); m_db->setPassword(""); m_db->setUserName(""); if(m_db->open()) { m_model->setQuery("select * from Produit"); ui->tableView->setModel(m_model); }else QMessageBox::critical(this,"Erreur data base",m_db->lastError().text());@
but when i want to instert data i got an error "Driver not loaded"
@ m_query->prepare("insert into Produit (Reference,Designation,localisation,Famille,Qte_min,Qte_max,Qte_stock,Unite,Prix_achat,Prix_vente) VALUES(:ref,:design,:local,:fam,:qtmin,:qtmax,:qtstock ,:unite,:pachat,:pvente)");
// santize data m_query->bindValue(":ref",ui->referenceLineEdit->text()); // QlineEdit m_query->bindValue(":design",ui->designationLineEdit->text()); // QlineEdit m_query->bindValue(":local",ui->localisaitonLineEdit->text()); // QlineEdit m_query->bindValue(":fam","Famille2"); // QcomboBox m_query->bindValue(":qtmin",ui->stockMinimaleLineEdit->text().toFloat()); // QlineEdit m_query->bindValue(":qtmax",ui->stockMaximaleLineEdit->text().toFloat()); // QlineEdit m_query->bindValue(":qtstock",ui->stockInitialeLineEdit->text().toFloat()); // QlineEdit m_query->bindValue(":unite","unite"); // QlineEdit m_query->bindValue(":pachat",ui->prixDAchatLineEdit->text().toFloat()); // QlineEdit m_query->bindValue(":pvente",ui->prixDeVenteLineEdit->text().toFloat()); // QlineEdit m_db->open(); if(m_query->exec()) { QMessageBox::information(this,tr("Donnée insérer"),tr("les donnée sont insérer avec success")) ; }else{ QMessageBox::critical(this,tr("Requette Erreur"), m_query->lastError().text()); }@
-
Hello,
I have just typed this, and it works OK:
@
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("C:/test.sb");
if (!db.open()) {
QMessageBox::critical(this, "Error", db.lastError().text());
return;
}QSqlQuery qu(db); qu.prepare("INSERT INTO Produit (Reference, Localisation, Famile) " " VALUES (:ref, :local, :fam)"); qu.bindValue(":ref", "Reference"); qu.bindValue(":local", "Local"); qu.bindValue(":fam", "Famile"); if (qu.exec()) { QMessageBox::information(this, "OK", "Row Inserted"); } else { QMessageBox::critical(this, "Error", qu.lastError().text()); }
@
-
[quote author="joejoshw" date="1376570605"]Hello,
I have just typed this, and it works OK:
@
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("C:/test.sb");
if (!db.open()) {
QMessageBox::critical(this, "Error", db.lastError().text());
return;
}QSqlQuery qu(db); qu.prepare("INSERT INTO Produit (Reference, Localisation, Famile) " " VALUES (:ref, :local, :fam)"); qu.bindValue(":ref", "Reference"); qu.bindValue(":local", "Local"); qu.bindValue(":fam", "Famile"); if (qu.exec()) { QMessageBox::information(this, "OK", "Row Inserted"); } else { QMessageBox::critical(this, "Error", qu.lastError().text()); }
@
[/quote]
yes you're right my error is herm_query !!
i don't spesify the db in m_query intialisation
@
m_query = new Qsqlquery(); // this wrong
mquery = new Qsqlquer(m_db) ; this is right@