1

I am currently working on a coursework project for school and it is a database system with a user interface using Tkinter, Python and SQLite3. I have made a form to add, delete, update and search for customers. The update function is not producing any errors, however, the changes are not being made to the .db file. Could anyone please have a look and maybe tell me where I have went wrong? I will attach photos of the user interface and the code for the function. I'm not used to using StackOverflow, so please let me know if I have left anything out or if you need more information. Thank you in advance.

    def UpdateCustomer(self):
        customerid = self.CustomerEntry.get();
        town = self.TownEntry.get();
        postcode = self.PostcodeEntry.get();
        with sqlite3.connect("LeeOpt.db") as db:
            cursor = db.cursor()
            update_customer = ('''UPDATE Customer 
            SET 
            Town = ?,
            Postcode = ?
            WHERE CustomerID = ?
            ''')
            db.commit()

            cursor.execute(update_customer,[(customerid),(town),(postcode)])
            tkinter.messagebox.showinfo("Notification","Customer record updated successfully")
            self.ClearEntries()

enter image description here

enter image description here

1 Answer 1

3

You must pass the parameter values that will replace the ? placeholdrs in the exact same order as they are in the sql statement:

cursor.execute(update_customer, (town, postcode, customerid))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.