Python 使用pyodbc更新数据库

Python 使用pyodbc更新数据库,python,sql-server,python-2.7,python-3.x,pypyodbc,Python,Sql Server,Python 2.7,Python 3.x,Pypyodbc,我在使用pyodbc模块更新数据库方面面临挑战。 没有错误,代码执行成功;但是SQL Server数据库没有更新。 正在从数据库获取数据 请检查: connection = pypyodbc.connect('Driver={SQL SERVER};Server=ser;Database=db;uid=uname;pwd=pass') cursor=connection.cursor() cursor.execute("declare @today as date;set @today =

我在使用pyodbc模块更新数据库方面面临挑战。 没有错误,代码执行成功;但是SQL Server数据库没有更新。 正在从数据库获取数据

请检查:

connection = pypyodbc.connect('Driver={SQL SERVER};Server=ser;Database=db;uid=uname;pwd=pass')

cursor=connection.cursor()

cursor.execute("declare @today as date;set @today = convert(varchar,getdate(),101);Update dbo.Credentials_Mst Set Password='qwerty',lastModifiedOn=@today,ModifiedBy='abcd' where Username='abc';")

您需要提交更改。添加此行:

connection.commit()
执行
游标后。执行(…)

如果在关闭连接之前未提交,您将丢失所有更改