我正在Qt中编写库存控制程序,但是在插入数据时收到错误消息QSqlError("", "", "")
。问题是数据正在插入到SQLITE数据库中,但是我不确定错误的含义。
我用来将数据插入数据库的代码如下:
query_Account.prepare("INSERT INTO Customer(Company_Name, City, Phone_Number, Street_Adress, County, BULSTAT, Company_Owner, Account_Since) "
"VALUES (:Company_Name, :City, :Phone_Number, :Street_Adress, :County, :BULSTAT, :Company_Owner, :Account_Since)");
query_Account.bindValue(":Company_Name", ui->lineEdit_Company_Name->text());
query_Account.bindValue(":City", ui->lineEdit_City->text());
query_Account.bindValue(":Phone_Number", (ui->lineEdit_Phone_Num->text()).toInt());
query_Account.bindValue(":Street_Adress", ui->lineEdit_Street_Add->text());
query_Account.bindValue(":County", ui->lineEdit_County->text());
query_Account.bindValue(":BULSTAT", (ui->lineEdit_BULSTAT->text()).toInt());
query_Account.bindValue(":Company_Owner", ui->lineEdit_Company_Owner->text());
query_Account.bindValue(":Account_Since", 1776-07-04);
query_Account.exec();
qDebug() << "SQL query_Account:" << query_Account.executedQuery();
qDebug() << "SQL ERROR:" << query_Account.lastError();
您实际上并没有收到错误。您只是无条件地打印出了一个错误,即使您没有得到任何错误。
if (query_Account.exec()) {
// got no error, proceed
qDebug() << "Yay!";
} else {
// got an error, deal with it
qDebug() << query_Account.executedQuery();
qDebug() << query_Account.lastError();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句