Root0x
Root0x

Reputation: 123

Getting a QSqlError("", "", "") but the data is inserted

I am programming a Stock Control Program in Qt but when im inserting data I receive an error of QSqlError("", "", ""). The problem is that the data is being inserted into the SQLITE database but I'm unsure of what error means.

The code that I'm using to insert data into the database is below:

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

Upvotes: 0

Views: 2251

Answers (1)

Mat
Mat

Reputation: 206689

You're not in fact getting an error. You're just unconditionally printing out an error even if you didn't get one.

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

Upvotes: 4

Related Questions