Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
792 views
in Technique[技术] by (71.8m points)

python - How to delete the selected row in qtablewidget from both the table and the sqlite database?

I am trying to remove and item from both the qtablewidget and the sqlite database, currently only the item selected from the talbe is deleted, however the item shuld also be deleted from the sqlite database. The function below repsonds when the "Remove" button is clicked, and it should remove the item from the table and from the database, howver it only deletes from the table, how could I make to to delete from the database aswell?

This section should delete the item from both the table and sqlite database

def removeWorkout(self):
         self.tableWidget.removeRow(self.tableWidget.currentRow())#removes item selected from the table
         conn=sqlite3.connect("workoutlist.db")
         c=conn.cursor()
         c.execute("DELETE FROM WorkoutList WHERE MuscleGroup LIKE ?",[self.tableWidget.currentRow])#removes item that was selected in the table from the database
         c.commit()

In the code above only removing the selected item works and it only removes it from the table, how could I make it to delete the item from the database aswell.

question from:https://stackoverflow.com/questions/65853830/how-to-delete-the-selected-row-in-qtablewidget-from-both-the-table-and-the-sqlit

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...