我有以下脚本运行
from os import getenv
import pyodbc
import os
import sys
cnxn = pyodbc.connect('''
DRIVER={ODBC Driver 13 for SQL Server};SERVER=myServer\SQLEXPRESS;
DATABASE=myTable;UID=myID;PWD=myPassword''')
cursor = cnxn.cursor() #makes connection
cursor.execute("""
UPDATE ShowroomCal
SET ShowroomCal.isbusy = 'Yes'
FROM ShowroomCal
JOIN calendarbookings on calendarbookings.date=showroomcal.style112 AND calendarbookings.showroom=ShowroomCal.showroom_name
WHERE CalendarBookings.date = showroomcal.style112 and ShowroomCal.Year='2018'
""") #runs update statement
row_count = cursor.rowcount #counts afrfected rows
status_msg = "result returned. {} row(s) affected."
print(status_msg.format(row_count)) #prints affected rows
cnxn.close()
notebook单元格返回“3行受影响”。然而,在sqlexpress中查看时,正在更新的表没有更改。在
从那以后,我在一个查询窗口中独立地从SQLServer管理中运行了这条语句,它立即改变了可能受到影响的三行,因此我知道表中的数据是存在的,并且该语句是有效的——至少从SQL的角度来看是这样的。在
有人能从Python的角度发现错误吗?在
Scratch'N'Purr为我提供了答案,非常感谢。在
如果其他人也有同样的问题,那就是缺乏
在陈述之后就是问题所在。我已经测试过了,效果很好。在
相关问题 更多 >
编程相关推荐