以下是我的代码,我想实现日期增添天数,但为什么会出现数据转换错误的问题
数据库模块代码
def update(rbook: Rbook) -> int:
"""
更新数据
:param s_book:
:return:
"""
con = None
try:
con = dbUtil.getCon()
cursor = con.cursor()
# 更新数据
sql = f"UPDATE borrow set returnDate= DATEADD(week,1,'returnDate='{rbook.returnDate}'') where bid='{rbook.bid}'"
cursor.execute(sql)
con.commit()
return cursor.rowcount
except Exception as e:
print(f"更新数据时发生错误: {e}")
if con is not None:
con.rollback()
return 0
finally:
dbUtil.closeCon(con)
功能实现代码
def update(self):
time = self.timeInput.text()
borrow2 = Rbook.my_construtor2(None, None, None, time)
if borrowDao.add(borrow2) is not None:
self.x = show_custom_message_box("系统提示", "借阅成功!")
self.resetForm()
self.initTable()
else:
self.x = show_custom_message_box("系统提示", "借阅失败!")
"Conversion failed when converting the varchar value '2024-04-26' to data type int