A
A
Alexey Mairin2017-09-14 17:29:57
C++ / C#
Alexey Mairin, 2017-09-14 17:29:57

C++ QT why query to sql Lite DB doesn't work?

Hello everyone!)
Actually, for some reason, the entry into the database of the values ​​entered in the edit does not work.
The request from the database works, that is, to check if there are any fields there, it comes out, but there are some problems with this.
Here is the function code:

QMessageBox mess;
    QString Name,Email,Password;

    Name=ui->lineEdit->text();
    Email=ui->lineEdit_2->text();
    Password=ui->lineEdit_3->text();


    QSqlDatabase regDB;
    regDB=QSqlDatabase::addDatabase("QSQLITE");
    regDB.setDatabaseName("D:\\database.db3");
    if(!regDB.open())
    {
        ui->label->setText("Data Base isn't open");
    }
    QSqlQuery query;

    query.prepare("INSERT INTO  People (Name, Password, E-mail) VALUES(?, ?, ?)");
   query.addBindValue(Name);
     query.addBindValue(Password);
     query.addBindValue(Email);

   if(query.exec())
   {
       qDebug()<<"All ok";
      }
   else
       qDebug()<<"loseee";

    mess.setText("Register is secseful");
    mess.exec();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2017-09-14
@m_avrina

No, your solution is non-generic and your mistake is not escaping the E-mail identifier.
Try [E-mail].
(Escaping is often used `E-mail`, but it doesn't work in SqLite, it's MySQL specific.)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question