繁体   English   中英

使用 Python 和 SQLite3 创建更新记录 Function

[英]Creating an Update Record Function using Python and SQLite3

我目前正在为学校做一个课程项目,它是一个使用 Tkinter、Python 和 SQLite3 的用户界面的数据库系统。 我已经制作了一个表格来添加、删除、更新和搜索客户。 更新 function 不会产生任何错误,但是不会对 .db 文件进行更改。 任何人都可以看看,也许可以告诉我哪里出错了? 我将附上用户界面的照片和 function 的代码。 我不习惯使用 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()

在此处输入图像描述

在此处输入图像描述

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM