Python-SQL更新操作;没有错误,但实际上并没有更新我的数据库

时间:2013-04-11 12:50:11

标签: python sql sql-update

我使用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)

2 个答案:

答案 0 :(得分:1)

您忘了parameters

        nameChange1 = self.TextField2.get()
        CusNo = self.TextField1.get()
        c.execute("""
            UPDATE customer
            SET first_name = ?
            WHERE customer_id = ?""", (nameChange1, CusNo,) )

答案 1 :(得分:0)

代码不完整。这个类,我假设有CREATE TABLE函数。 另外,查看

的返回值
c.execute