英文:
pyodbc with msaccess: too few parameters. Trying to set date to yesterday in a column
问题
import pyodbc
conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\testing\mydb.accdb')
crs = conn.cursor()
crs.execute('UPDATE [testtable] SET "dateoflastchange" = DateAdd("d", -1, Date())')
# Too few parameters. Expected 1
英文:
import pyodbc
conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\testing\mydb.accdb')
crs = conn.cursor()
crs.execute('UPDATE [testtable] SET "dateoflastchange" = DATEADD("d", -1, DATE())')
# Too few parameters. Expected 1
I tried replacing DATEADD with DateAdd and replacing commas with semi-colons. Also "day" instead of "d" as seen in other examples. I cannot figure it out. In the past it was usually some Microsoft syntax that I had wrong. Where did he expect 1 parameter but got 0?
答案1
得分: 1
Solution:
crs.execute("UPDATE [testtable] SET [dateoflastchange] = DATEADD('d', -1, DATE())")
I had to use brackets as mentioned by Gustav and swap the quotes.
英文:
Solution:
crs.execute("UPDATE [testtable] SET [dateoflastchange] = DATEADD('d', -1, DATE())")
I had to use brackets as mentioned by Gustav and swap the quotes.
答案2
得分: 0
尝试使用Access SQL语法:
crs.execute('UPDATE [testtable] SET [dateoflastchange] = DATEADD("d", -1, DATE())')
英文:
Try with Access SQL syntax:
crs.execute('UPDATE [testtable] SET [dateoflastchange] = DATEADD("d", -1, DATE())')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论