【问题标题】:Creating an Update Record Function using Python and SQLite3使用 Python 和 SQLite3 创建更新记录函数
【发布时间】:2021-04-14 10:00:06
【问题描述】:

我目前正在为学校做一个课程项目,它是一个带有使用 Tkinter、Python 和 SQLite3 的用户界面的数据库系统。我已经制作了一个表格来添加、删除、更新和搜索客户。更新功能不会产生任何错误,但是,不会对 .db 文件进行更改。任何人都可以看看,也许可以告诉我哪里出错了?我将附上用户界面的照片和功能的代码。我不习惯使用 StackOverflow,所以如果我遗漏了任何内容或者您需要更多信息,请告诉我。提前谢谢你。

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

【问题讨论】:

    标签: python database sqlite tkinter


    【解决方案1】:

    您必须传递将替换 ? 占位符的参数值,其顺序与它们在 sql 语句中的顺序完全相同:

    cursor.execute(update_customer, (town, postcode, customerid))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-12
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-08
      • 2016-05-19
      相关资源
      最近更新 更多