My favorites | Sign in
Project Home Downloads Wiki
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 241: Cannot insert record into MS Access DB
2 people starred this issue and may be notified of changes. Back to list
Status:  NoFix
Owner:  ----
Closed:  Sep 2012


 
Reported by ramax...@gmail.com, Feb 27, 2012
Im trying to add record to the database. There is code i have:

import pyodbc, os

database = os.getcwd()+'\\DB.accdb'
if os.path.exists(database):
    print 'DB exists!'
else:
    print 'Database not found!!!'
    exit()
    
constr = 'Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=%s;'  % database
conn = pyodbc.connect(constr)
cur = conn.cursor()

sql = "INSERT INTO clients_test (name,mailTo,mailCC,mailBCC,mailbox,description) VALUES (1,2,3,4,5,6)"
cur.execute(sql)

sql = "select * from clients_test"
cur.execute(sql)

result = cur.fetchall()
for item in result:
    print item

cur.close()
conn.close()


console output:
DB exists!
(47, u'1', u'2', u'3', u'4', u'5', u'6')


but when i open the database, the database is empty
Feb 29, 2012
#1 davidp.r...@gmail.com
Autocommit defaults to False so you need to set it to True to keep your changes.
Sep 13, 2012
#2 pyneha...@gmail.com
Try this

sql = ("INSERT INTO client_test (name,mailTo,mailCC,mailBCC,mailbox,description) VALUES(1,2,3,4,5,6);")
cur.execute(sql)
cur.commit(sql)
Sep 29, 2012
Project Member #3 mkleehammer
(No comment was entered for this change.)
Status: NoFix

Powered by Google Project Hosting