Can't delete information from table made with information pulled from sqlite3
-
Hello,
I enter the information first through the interface, then register it. There is no problem here. But I cannot delete the data inserted in the table.
Interface code: from PyQt5 import QtWidgets from PyQt5.QtWidgets import QTableWidgetItem, QHeaderView from Ui_tamir import Ui_Dialog import sys import os import sqlite3 as sql os.system("python Baglan.py") os.system("python TabloOlustur.py") global urunno, alacakkisiadsoyad, telno, esya, parca, yapilacaklar, fiyat class Window(QtWidgets.QMainWindow): def __init__(self): super(Window, self).__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.formYukle() self.ui.kaydetButon.clicked.connect(self.butonKaydetTiklandi) self.ui.silButon.clicked.connect(self.sil) def formYukle(self): self.ui.eklenenlerTablo.clear() self.ui.eklenenlerTablo.setColumnCount(7) self.ui.eklenenlerTablo.setHorizontalHeaderLabels(("Urun NO", "Ad-soyad", "Telefon NO", "Esya", "Parca", "Yapilacaklar", "Fiyat")) self.ui.eklenenlerTablo.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch) db = sql.connect("bilgiler.db") cur = db.cursor() sorgu = "Select * from TBilgiler" cur.execute(sorgu) satirlar = cur.fetchall() self.ui.eklenenlerTablo.setRowCount(len(satirlar)) for satirIndeks, satirVeri in enumerate(satirlar): for sutunIndeks, sutunVeri in enumerate(satirVeri): self.ui.eklenenlerTablo.setItem(satirIndeks, sutunIndeks, QTableWidgetItem(str(sutunVeri))) def butonKaydetTiklandi(self): urunno = self.ui.urunNoGiris.toPlainText() alacakkisiadsoyad = self.ui.urunNoGiris_2.toPlainText() telno = self.ui.telNoGiris.toPlainText() esya = self.ui.esyaGiris.toPlainText() parca = self.ui.parcaGiris.toPlainText() yapilacaklar = self.ui.yapilacaklarGiris.toPlainText() fiyat = self.ui.fiyatGiris.toPlainText() try: self.baglanti = sql.connect("bilgiler.db") self.c = self.baglanti.cursor() self.c.execute("INSERT INTO TBilgiler Values(?, ?, ?, ?, ?, ?, ?)", (urunno, alacakkisiadsoyad, telno, esya, parca, yapilacaklar, fiyat)) self.baglanti.commit() self.c.close() print("Başarılı", "bilgiler başarıyla gönderildi") except: print("Hata", "Hata !!!!!!") def sil(self): uruno = self.ui.urunNoGiris.toPlainText() self.baglanti = sql.connect("bilgiler.db") self.c = self.baglanti.cursor() self.c.execute("DELETE FROM TBilgiler WHERE urunno = ?", (uruno,)) self.baglanti.commit() self.c.close() self.baglanti.close() print("Urun silindi") self.sil() self.formYukle() def app(): app = QtWidgets.QApplication(sys.argv) win = Window() win.show() sys.exit(app.exec_()) app()I think the problem is in this code:
```
def sil(self):
uruno = self.ui.urunNoGiris.toPlainText()self.baglanti = sql.connect("bilgiler.db") self.c = self.baglanti.cursor() self.c.execute("DELETE FROM TBilgiler WHERE urunno = ?", (uruno,)) self.baglanti.commit() self.c.close() self.baglanti.close() print("Urun silindi") self.sil() self.formYukle() -
Hello,
I enter the information first through the interface, then register it. There is no problem here. But I cannot delete the data inserted in the table.
Interface code: from PyQt5 import QtWidgets from PyQt5.QtWidgets import QTableWidgetItem, QHeaderView from Ui_tamir import Ui_Dialog import sys import os import sqlite3 as sql os.system("python Baglan.py") os.system("python TabloOlustur.py") global urunno, alacakkisiadsoyad, telno, esya, parca, yapilacaklar, fiyat class Window(QtWidgets.QMainWindow): def __init__(self): super(Window, self).__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.formYukle() self.ui.kaydetButon.clicked.connect(self.butonKaydetTiklandi) self.ui.silButon.clicked.connect(self.sil) def formYukle(self): self.ui.eklenenlerTablo.clear() self.ui.eklenenlerTablo.setColumnCount(7) self.ui.eklenenlerTablo.setHorizontalHeaderLabels(("Urun NO", "Ad-soyad", "Telefon NO", "Esya", "Parca", "Yapilacaklar", "Fiyat")) self.ui.eklenenlerTablo.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch) db = sql.connect("bilgiler.db") cur = db.cursor() sorgu = "Select * from TBilgiler" cur.execute(sorgu) satirlar = cur.fetchall() self.ui.eklenenlerTablo.setRowCount(len(satirlar)) for satirIndeks, satirVeri in enumerate(satirlar): for sutunIndeks, sutunVeri in enumerate(satirVeri): self.ui.eklenenlerTablo.setItem(satirIndeks, sutunIndeks, QTableWidgetItem(str(sutunVeri))) def butonKaydetTiklandi(self): urunno = self.ui.urunNoGiris.toPlainText() alacakkisiadsoyad = self.ui.urunNoGiris_2.toPlainText() telno = self.ui.telNoGiris.toPlainText() esya = self.ui.esyaGiris.toPlainText() parca = self.ui.parcaGiris.toPlainText() yapilacaklar = self.ui.yapilacaklarGiris.toPlainText() fiyat = self.ui.fiyatGiris.toPlainText() try: self.baglanti = sql.connect("bilgiler.db") self.c = self.baglanti.cursor() self.c.execute("INSERT INTO TBilgiler Values(?, ?, ?, ?, ?, ?, ?)", (urunno, alacakkisiadsoyad, telno, esya, parca, yapilacaklar, fiyat)) self.baglanti.commit() self.c.close() print("Başarılı", "bilgiler başarıyla gönderildi") except: print("Hata", "Hata !!!!!!") def sil(self): uruno = self.ui.urunNoGiris.toPlainText() self.baglanti = sql.connect("bilgiler.db") self.c = self.baglanti.cursor() self.c.execute("DELETE FROM TBilgiler WHERE urunno = ?", (uruno,)) self.baglanti.commit() self.c.close() self.baglanti.close() print("Urun silindi") self.sil() self.formYukle() def app(): app = QtWidgets.QApplication(sys.argv) win = Window() win.show() sys.exit(app.exec_()) app()I think the problem is in this code:
```
def sil(self):
uruno = self.ui.urunNoGiris.toPlainText()self.baglanti = sql.connect("bilgiler.db") self.c = self.baglanti.cursor() self.c.execute("DELETE FROM TBilgiler WHERE urunno = ?", (uruno,)) self.baglanti.commit() self.c.close() self.baglanti.close() print("Urun silindi") self.sil() self.formYukle() -
Hi,
Did you check that your database calls are successful ?
Did you also consider using Qt's SQL module ?