获取QSqlError("","","")但是插入了数据

时间:2014-12-22 14:41:36

标签: c++ database qt sqlite

我正在编写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();

1 个答案:

答案 0 :(得分:4)

您实际上并未收到错误消息。即使您没有获得错误,您也会无条件地打印错误。

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();
}