0

Im using python and SQL to make a database for customer accounts. I am trying to give the option to update a customer's details. I have done what I believe would update the table but when I print the contents nothing has changed. Please can you tell me where I am going wrong?

def update_Customer(self):
    # create sqlite connection            
    conn = sqlite3.connect("lanyard.db", timeout=5)
    c = conn.cursor()
    # if texfield is empty
    if self.TextField1.get() !="":
        if self.TextField2.get() != "":
            nameChange1 = self.TextField2.get()
            CusNo = self.TextField1.get()
            c.execute("""
                UPDATE customer
                SET first_name = 'nameChange1'
                WHERE customer_id = 'CusNo'""")
            conn.commit()
        if self.TextField3.get() != "":
            nameChange2 = self.TextField3.get()
            CusNo = self.TextField1.get()
            c.execute("""
                UPDATE CUSTOMER
                SET second_name = 'nameChange2'
                WHERE customer_id = 'CusNo'""")
            conn.commit()
        if self.TextField4.get() == "":
            nameChange3 = self.TextField4.get()
            CusNo = self.TextField1.get()
            c.execute("""
                UPDATE CUSTOMER
                SET address = 'nameChange3'
                WHERE customer_id = 'CusNo'""")
            conn.commit()
    conn.commit()
    c.close()

    # clear input
    self.TextField1.delete(0, END)
    self.TextField2.delete(0, END)
    self.TextField3.delete(0, END)
    self.TextField4.delete(0, END)

2 Answers 2

1

You forgot parameters:

        nameChange1 = self.TextField2.get()
        CusNo = self.TextField1.get()
        c.execute("""
            UPDATE customer
            SET first_name = ?
            WHERE customer_id = ?""", (nameChange1, CusNo,) )
Sign up to request clarification or add additional context in comments.

2 Comments

nameChange1 should be a parameter too.
I had already tried adding those parameters in but got an error, tried again as you did it and got the same error. Exception in Tkinter callback Traceback (most recent call last): File "C:\Python32\lib\tkinter_init_.py", line 1399, in call return self.func(*args) File "J:\University\U08007\D\SQL_Lanyard_GUI1.py", line 343, in update_Customer WHERE customer_id = 'CusNo'""", (nameChange1, CusNo,)) sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are 2 supplied.
0

The code is not complete. The class, I am assuming has CREATE TABLE function. Additionally, look at return value of

c.execute

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.