0

我使用 python 和 SQL 为客户帐户创建数据库。我正在尝试提供更新客户详细信息的选项。我已经完成了我认为会更新表格的操作,但是当我打印内容时,什么都没有改变。请你能告诉我哪里出错了吗?

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)
4

2 回答 2

1

您忘记了参数

        nameChange1 = self.TextField2.get()
        CusNo = self.TextField1.get()
        c.execute("""
            UPDATE customer
            SET first_name = ?
            WHERE customer_id = ?""", (nameChange1, CusNo,) )
于 2013-04-11T13:00:15.567 回答
0

代码不完整。我假设该类具有 CREATE TABLE 功能。另外,看看返回值

c.execute
于 2013-04-11T13:00:01.453 回答