【问题标题】:Updating database using pypyodbc使用 pypyodbc 更新数据库
【发布时间】:2017-06-01 14:42:14
【问题描述】:

我在使用 pypyodbc 模块更新数据库时面临挑战。 没有报错,代码执行成功;但 SQL-Server DB 未更新。 正在从 DB 中获取数据。

请检查:

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';")

【问题讨论】:

    标签: python sql-server python-2.7 python-3.x pypyodbc


    【解决方案1】:

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

    connection.commit()
    

    在你做cursor.execute(...)之后。

    如果您在关闭连接之前不commit,您将丢失所有更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-10
      • 2014-12-21
      • 1970-01-01
      • 2011-11-17
      • 1970-01-01
      • 2017-04-28
      相关资源
      最近更新 更多