How to display and update QTablewidget with a row record after an sql insertion statement is executed
Unsolved
Qt for Python
-
How to display details in qtableWidget right after an sql insertion statement is executed. Then whenever a second insertion is made, is there a way to update the table to show a second insertion statement in same QtableWidget. Below is what I tried but it;
id_no = self.ui.lineEdit_13.text() user_role = self.ui.comboBox_21.currentText() try: sql_queries = "INSERT INTO users (id_no,user_role) VALUES(?,?,?,?,?,?)" cur.execute(sql_queries, (staff_no, user_role)) con.commit() for row_number, check in enumerate(check_exists): self.ui.tableWidget_8.insertRow(row_number) for column_number, data in enumerate(check): cell = QtWidgets.QTableWidgetItem(str(data)) self.ui.tableWidget_8.setItem(row_number, column_number, cell) except Exception as e: print(e)
-
Hi,
Your SQL statement looks wrong as you have more bind parameters than actual parameters. That set aside, there's no relation in your code between your insert statement, the actual content of the database and the variables you use to create and out that new item in your QTableWidget.
On a side note, Qt has a SQL module that is also designed to work with its model / view classes.