我有一个SQL数据库“车库.db“有3个表: 客户、汽车和汽车
当有人在Car表中输入注册信息时,我想更新MOT表中的BookedMOT字段。有人能帮我用SQL查询,可以做到这一点,谢谢。你知道吗
我用tkinter在Python3.6中编写了这个代码。这是我的尝试
def Booked(self):
date = Date.get()
month = Month.get()
year = Year.get()
BookedMOT = (date + '/' + month + '/' + year)
Registration = self.RegistrationEnt.get()
with sqlite3.connect('Garage.db') as db:
cursor = db.cursor()
add_date = ('UPDATE MOT SET MOT.BookedMOT = ? FROM Car WHERE Car.Registration = ?')
cursor.execute(add_date,[(BookedMOT), (Registration)])
db.commit()
(这解决了一些Python问题,我甚至在意识到SQL看起来不对劲之前就注意到了,这可能应该首先修复)
试试这个:
一般来说,当您说
with ... as x:
时,您可能应该在with
块内使用x
。块完成后,它会自动提交,然后尝试使用db
或cursor
可能是不正确的。with
也意味着你不必再db.commit()
。你知道吗sqlite3 connection objects (^{} in this case) have an ^{} method:
最后,有一些多余的括号可以删除。你知道吗
相关问题 更多 >
编程相关推荐