I have buttons in the combobox where I view DB data so I can edit, delete, and update the data I selected. When I press the edit button of a db data I selected in Combobox, I transfer it to qlineedit, but when you make changes and click the update button, all the database data is updated instead of the db data I selected. As you can see in my code example below, this is normal. What I want to do is just update the data I've selected.
etc :
sampleId = select
cur.execute("UPDATE SampledB SET NAME=? WHERE ID=?", (SName, sampleId))
I want to know how I should make changes to my code to get the result I want. I would really appreciate it if you could enlighten me on this matter. I am trying to learn this business with my own curiosity and improve myself. On top of that, I have not studied in any school on this profession, so the question I ask is very easy for you due to my insufficient knowledge, but it is just as difficult for me. My final point in my current research is to use SELECT in the UPDATE command. I don't know if this way is correct either, so I'm trying to research it and learn how to use it. I don't know if it will work once I find out.
def update(self): con = sqlite3.connect('DataBase.db') cur = con.cursor() message = QMessageBox.question(self, "SAMPLE", "Are you sure you want to update the record??", QMessageBox.Yes | QMessageBox.No) if message == QMessageBox.Yes: try: select = self.ui.combo_SampleName.currentText() SName = self.ui.line_SampleDbUpdateAdd.text() cur.execute("UPDATE SampledB SET NAME=?", [SName]) con.commit() self.ui.combo_SampleName.clear() sampleComboList(self) self.ui.label_SampleCenteRightSpace.setText("REGISTRATION UPDATED") except Exception as Error: self.ui.label_SampleCenteRightSpace.setText("AN UNEXPECTED ERROR OCCURRED UPDATE FAILED") else: self.ui.label_SampleCenteRightSpace.setText("REGISTRATION UPDATE CANCELED")I do not have the id of the data in the combobox, I cannot assign a variable and WHERE Id=? I can't follow a path. However, id is automatically assigned when registering on Db. What I'm trying to do is just select a data from the Combobox and update only that data. I've done so much research but couldn't get any results other than confusion.
etc :
sampleId = select
cur.execute("UPDATE SampledB SET NAME=? WHERE ID=?", (SName, sampleId))
I want to know how I should make changes to my code to get the result I want. I would really appreciate it if you could enlighten me on this matter. I am trying to learn this business with my own curiosity and improve myself. On top of that, I have not studied in any school on this profession, so the question I ask is very easy for you due to my insufficient knowledge, but it is just as difficult for me. My final point in my current research is to use SELECT in the UPDATE command. I don't know if this way is correct either, so I'm trying to research it and learn how to use it. I don't know if it will work once I find out.