'I'm trying to create a function to delete data from the database by Python(PyQt5)
I'm trying to create a function to delete Mysql data from a tableWidget but I'm not getting it, could someone help me?
This is my code:
banco = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="",
database="controle_teste"
)
class telaprocurar(QDialog):
def __init__(self,*args,**argvs):
super(telaprocurar,self).__init__(*args,**argvs)
self.ui = Ui_procurar()
self.ui.setupUi(self)
self.ui.pushButton.clicked.connect(self.pesquisar)
self.ui.pushButton_2.clicked.connect(self.gerarpdf)
self.ui.pushButton_4.clicked.connect(self.can)
self.ui.pushButton_5.clicked.connect(self.dell)
def pegaselecaodobanco(self):
return self.ui.tableWidget.currentRow()
def pegaselecaodatabela(self):
valor = self.ui.tableWidget.item(self.pegaselecaodobanco(),0)
return valor.text()
def dell(self):
try:
cursor = banco.cursor()
id = self.pegaselecaodatabela()
print(id)
cursor.execute(f"DELETE FROM beneficio WHERE id = {id} ")
QMessageBox.information(QMessageBox(), "SUCESSO", "DADOS EXCLUIDOS COM SUCESSO!!!")
except:
QMessageBox.warning(QMessageBox(),"ERRO", "OCORREU UM ERRO, TENTE NOVAMENTE")
it finds the ID in the bank but does not delete.I'm trying to create a function to delete Mysql data from a tableWidget but I'm not getting it, could someone help me?
it finds the ID in the bank but does not delete. what appears: built-in function id
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
