我有一个我想要修改的数据库文件。因此我使用pyodbc和以下代码:
import pyodbc
myDbFile = r"D:\Users\Tobias\Documents\database.db"
myPass = u'*****'
cnx = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ=%s;PWD=%s;Charset=utf-8' % (myDbFile, myPass))
cursor = cnx.cursor()
# reading any database entry
cursor.execute('SELECT ID, Title, Tag FROM Dox')
mydata = cursor.fetchall()
print mydata[34]
# -> returns ('010CC005-4A8A-4AB3-8B98-E431D3BB328B', u'itemTitle', None)
# The following line works fine
cursor.execute('UPDATE Dox SET Tag=30 WHERE Title = ?', u'itemTitle')
# But this doesn't -> nothing is changed
cursor.execute('UPDATE Dox SET Tag=30 WHERE ID = ?', '010CC005-4A8A-4AB3-8B98-E431D3BB328B')
cnx.commit()
cnx.close()
我完全不知道为什么要通过ID&ID进行识别。不起作用。你有什么提示吗?
答案 0 :(得分:0)
在指定复制ID值时,访问可能有点繁琐,我能够在发布时重新创建您的问题。但是,将ID值包装在大括号中对我有用:
cursor.execute('UPDATE Dox SET Tag=30 WHERE ID = ?', '{010CC005-4A8A-4AB3-8B98-E431D3BB328B}')