Link to home
Start Free TrialLog in
Avatar of nomoslogos
nomoslogos

asked on

Can't write to MSAccess database with pyodbc

I am using the Python code below to write to an MSAccess DB through ODBC. I don't get any errors, I know the database is being accessed because it creates a key, but the database isn't close (until I close the Python session) because the key doesn't go away. But no data is getting written to the database.

Can anyone see what I am not?

btw, Customer_ID is an integer.

import pyodbc
cnxn = pyodbc.connect("DSN=proddb")
cnxn.execute("INSERT INTO tblParts (Part_Number, Part_Description, Customer_ID, Part_Type) VALUES ('856854-001', 'BASEFRAME', 421, 'NA')")
cnxn.close
Avatar of nomoslogos
nomoslogos

ASKER

A search on EE comes with with no questions regarding PYODBC...
Also, no error messages are generated...
>>> 
>>> 
Where you have this:

  cnxn.close

you need this:

  cnxn.close()

Without the (), the function doesn't get called.

Thanks RichieHindle, it does open & close the database now, but still no data is getting written. Maybe it has to be opened in a specific mode?
ASKER CERTIFIED SOLUTION
Avatar of RichieHindle
RichieHindle

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks again, RichieHindle! That was it!