[Tutor] pyodbc/date values in MS Access
Alan Gauld
alan.gauld at btinternet.com
Wed Dec 15 12:50:43 CET 2010
"Albert-Jan Roskam" <fomcl at yahoo.com> wrote
> dates. Below, snippet #1 does not work (Access says the inserted
> value is not
> consistent with the defined datatype), but #2 does.
#2 is just normal string formatting so should always work.
But the cursor method is presumabnly doing some kind
of data type checking. What kind of data type does Access
normally expect for a date? Is it just a formatted string? Or
is there perhaps a numeric or datetime format that the
execute() might be expecting?
> ### 1
> sql = "INSERT INTO tblSomeTable (myDate) VALUES (?);"
> cursor.execute(sql, "#01/01/2010#")
>
> ### 2
> sql = "INSERT INTO tblSomeTable (myDate) VALUES (%s);"
> cursor.execute(sql % "#01/01/2010#")
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list