pyodbc与msaccess:参数太少。尝试将日期设为昨天放入列中

huangapple go评论67阅读模式
英文:

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())')

huangapple
  • 本文由 发表于 2023年5月26日 16:34:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76339067.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定