pyodbc with msaccess: too few parameters. Trying to set date to yesterday in a column

32 views Asked by At
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?

2

There are 2 answers

0
R-obert On

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
Gustav On

Try with Access SQL syntax:

crs.execute('UPDATE [testtable] SET [dateoflastchange] = DATEADD("d", -1, DATE())')