I can delete specific rows using manual SQL query command. But can not delete from QLineEdit
. How to bind with QLineEdit
?
我可以使用手动SQL查询命令删除特定的行。但无法从QLineEdit中删除。如何与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?
查询已执行但未删除。我究竟做错了什么?
1 个解决方案
#1
1
The syntax doesn't look right and you call query->exec()
twice. This is how you should run the prepared statement:
语法看起来不正确,您调用query-> exec()两次。这是你应该如何运行预准备语句:
QSqlQuery query = new QSqlQuery(databaseInstance);
bool ok = query->prepare(deleteStatement);
if (!ok) {
qWarning() << "SQL error:" << deleteStatement;
}
query->bindValue(":person_name", person_name);
query->exec();
#1
1
The syntax doesn't look right and you call query->exec()
twice. This is how you should run the prepared statement:
语法看起来不正确,您调用query-> exec()两次。这是你应该如何运行预准备语句:
QSqlQuery query = new QSqlQuery(databaseInstance);
bool ok = query->prepare(deleteStatement);
if (!ok) {
qWarning() << "SQL error:" << deleteStatement;
}
query->bindValue(":person_name", person_name);
query->exec();