0

Hello I have tried every forum and resource i have and can still not find the answer to my question.

I am making a booking management system. One of the features is the admin can search someones email and get their details from the database. So i put a line edit so i can get the QString from the email and then i tried to parse it into a SQL query. Thought this would be easy but QT said no. so i am at a complete loss.

Any help will be much appreciated.

The code:

QString email = ui->lineEdit_custsearch->text();

QSqlQuery qry;

QString dets = "SELECT firstname FROM customer WHERE email=="+email+"";

if (qry.exec(dets))
{
    for (int i = 0;qry.next();i++)
    {
        ui->lineEdit_first->setText(qry.value(0).toString());
    }
}

1 Answers1

0

In SQL you only need to use a single '=', sign, might be worth giving that a try?

SELECT firstname FROM customer WHERE email="+email+"

Just a suggestion, to make it more readable, it might be worth using string interpolation too so something like the below:

string email = '';
QString dets = $"SELECT firstname FROM customer WHERE email='{email}'";
Jack
  • 1
  • 1