使用Python和SQLite3创建更新记录函数
我目前正在为学校做一个课程项目,它是一个数据库系统,带有使用Tkinter、Python和SQLite3的用户界面。我已经做了一个表单来添加、删除、更新和搜索客户。update函数没有产生任何错误,但是没有对.db文件进行更改。谁能看一下,告诉我哪里出了问题?我将附上用户界面的照片和功能代码。我不习惯使用StackOverflow,所以如果我遗漏了什么或者您需要更多信息,请告诉我。先谢谢你使用Python和SQLite3创建更新记录函数,python,database,sqlite,tkinter,Python,Database,Sqlite,Tkinter,我目前正在为学校做一个课程项目,它是一个数据库系统,带有使用Tkinter、Python和SQLite3的用户界面。我已经做了一个表单来添加、删除、更新和搜索客户。update函数没有产生任何错误,但是没有对.db文件进行更改。谁能看一下,告诉我哪里出了问题?我将附上用户界面的照片和功能代码。我不习惯使用StackOverflow,所以如果我遗漏了什么或者您需要更多信息,请告诉我。先谢谢你 def UpdateCustomer(self): customerid = se
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()
必须传递将替换的参数值?placeholder的顺序与sql语句中的顺序完全相同:
cursor.execute(update_customer, (town, postcode, customerid))
必须传递将替换的参数值?placeholder的顺序与sql语句中的顺序完全相同:
cursor.execute(update_customer, (town, postcode, customerid))