I am able to get the index of the selected row of the QTableView as follow:
row_index= ui->tableView->currentIndex().row();
I need to be able to pass this row_index to a SELECT query to select the Primary key in that row. Then use that primary_key in a DELETE query to delete that record in the database (or edit it). But, I don't know how !!
Currently, I am hardcoding the primary_key the following:
QString PRIMARY_KEY = "3"
QString ref_no = PRIMARY_KEY;
query.prepare("DELETE FROM personal_Info WHERE ref_no =(:ref_no)");
query.bindValue(":ref_no",ref_no);
if (!query.exec())
{
qDebug() << "Error" << query.lastError().text();
return false;
}
return true;
... and it is working. The record where ref_no = 3 is deleted (or 4 or what ever number as long as it is exist in that table and in that field)
But I cannot get the primary_key of that record when select a row in QTableView that showing QSqlQueryModel.
Aucun commentaire:
Enregistrer un commentaire