Updating records using QSqlTableModel
-
Hi there!
I'm working with MySql. I have got a table called product, and it has some fields(name, producer, barcode, cost, amount). I should insert data from GUI, so I'm using QTableView and QSqlTableModel:
QSqlTableModel *model = new QSqlTableModel(this, database);//database - QDataBase, and is open model->setTable(product);//for inserting, I don't need all data in product, so I don't select() model->setEditStrategy(QSqlTableModel::EditStrategy::OnManualSubmit); ui->tableView->setModel(model);
And there's a button calles Submit. Whet it is pressed, the data should be updated if it is exists in product table, otherwise it should be inserted. If name column of a row in the table is in product, it's amount should be incremented to value in the row. But I have no idea how to do this, could you plz help?
-
Hi there!
I'm working with MySql. I have got a table called product, and it has some fields(name, producer, barcode, cost, amount). I should insert data from GUI, so I'm using QTableView and QSqlTableModel:
QSqlTableModel *model = new QSqlTableModel(this, database);//database - QDataBase, and is open model->setTable(product);//for inserting, I don't need all data in product, so I don't select() model->setEditStrategy(QSqlTableModel::EditStrategy::OnManualSubmit); ui->tableView->setModel(model);
And there's a button calles Submit. Whet it is pressed, the data should be updated if it is exists in product table, otherwise it should be inserted. If name column of a row in the table is in product, it's amount should be incremented to value in the row. But I have no idea how to do this, could you plz help?
@Abdurahman_Gulamkadirov
This is all standard/straightforward. You should have read
https://doc.qt.io/qt-5/sql-model.html#the-sql-table-model
https://doc.qt.io/qt-5/qsqltablemodel.html#detailsand some example like, say
https://programmer.group/sql-table-model-qsqltable-model.html -
@Abdurahman_Gulamkadirov
This is all standard/straightforward. You should have read
https://doc.qt.io/qt-5/sql-model.html#the-sql-table-model
https://doc.qt.io/qt-5/qsqltablemodel.html#detailsand some example like, say
https://programmer.group/sql-table-model-qsqltable-model.htmlThis post is deleted!