Reputation:
I can delete specific rows using manual SQL query command. But can not delete from QLineEdit
. How to bind with QLineEdit
?
Here is my code:
person_name = ui->txt_UserName->text ();
mobile_number = ui->txt_Pass->text ();
//delete values
QString deleteStatement = "DELETE FROM phonebook_info WHERE user_name = ':person_name'";
query->bindValue (":person_name", person_name);
query->exec (deleteStatement);
if(query->exec ()){
QMessageBox::information (this, "Information!", "Row Deleted.", QMessageBox::Ok);
ui->statusBar->showMessage ("Row Deleted.");
} else {
QMessageBox::critical (this, "Information!", "Row not Deleted.", QMessageBox::Ok);
ui->statusBar->showMessage ("Row not Deleted.");
}
query executed but not delete. What am I doing wrong?
Upvotes: 1
Views: 452
Reputation: 90853
The syntax doesn't look right and you call query->exec()
twice. This is how you should run the prepared statement:
QSqlQuery query = new QSqlQuery(databaseInstance);
bool ok = query->prepare(deleteStatement);
if (!ok) {
qWarning() << "SQL error:" << deleteStatement;
}
query->bindValue(":person_name", person_name);
query->exec();
Upvotes: 1