Hello all,
I would like your help concerning multiple sql queries in qt.
At the moment i am trying to insert in a table a value and the same time to check if this value is already exists in an other table. Could you please give me an example how this can be done?
Please see below how i tried to do it. I always get "Invalid device ID".
strQuery="INSERT INTO User VALUES ( :name, :psw, :dID)";
query.bindValue( ":name", ui.RUserNameLineEdit->text() );
query.bindValue( ":psw",ui.RPasswordLineEdit->text() );
if (ui.RUserNameLineEdit->text() == 0)
{
printf("Invalid UserName\n");
return;
}
if (ui.RPasswordLineEdit->text() == 0)
{
printf("Invalid password\n");
return;
}
if (ui.ConfirmPassword->text() == 0)
{
printf("Invalid password\n");
return;
}
if (ui.RClientLineEdit->text() == 0)
{
printf("Invalid password\n");
return;
}
query.exec(strQuery);
strQuery="SELECT * from Clientwhere DeviceID='%1'";
if (ui.RClientLineEdit->text() != "DeviceID")
{
printf("Invalid DeviceID\n");
return;
}
query.exec(strQuery);
QSqlQuery query;
QString strQuery;
strQuery="INSERT INTO User VALUES ( :name, :psw, :dID)";
query.bindValue( ":name", ui.RUserNameLineEdit->text() );
query.bindValue( ":psw",ui.RPasswordLineEdit->text() );
if (ui.RUserNameLineEdit->text() == 0)
{
printf("Invalid UserName\n");
return;
}
if (ui.RPasswordLineEdit->text() == 0)
{
printf("Invalid password\n");
return;
}
if (ui.ConfirmPassword->text() == 0)
{
printf("Invalid password\n");
return;
}
if (ui.RClientLineEdit->text() == 0)
{
printf("Invalid password\n");
return;
}
query.exec(strQuery);
strQuery="SELECT * from Clientwhere DeviceID='%1'";
if (ui.RClientLineEdit->text() != "DeviceID")
{
printf("Invalid DeviceID\n");
return;
}
query.exec(strQuery);
To copy to clipboard, switch view to plain text mode
Thank you in advance!
Bookmarks