Thanks.Now it works!It was the wrong column.
Thanks.Now it works!It was the wrong column.
Never deleted using this code:
Qt Code:
QModelIndexList selectedList = ui->tableView_clients->selectionModel()->selectedRows(); int selected_row; int i=0; selected_row=((selectedList.at(i).row())-1); QSqlQuery query; query.prepare("DELETE from clients where ClientId="+row); query.exec();To copy to clipboard, switch view to plain text mode
Try this :Qt Code:
QModelIndexList selectedList = ui->tableView_clients->selectionModel()->selectedRows(); int selected_row; int i=0; selected_row=((selectedList.at(i).row())-1); QSqlQuery query; query.prepare(my_query); query.exec();To copy to clipboard, switch view to plain text mode
Look what You get in my_query after line 9 and think why.
... and be aware that the model row number and and the ClientID are not necessarily related to each other in any way.
Why don't you use the model to QAbstractItemModel::removeRow() the selected item?
Bookmarks