| Issue 241: | Cannot insert record into MS Access DB | |
| 2 people starred this issue and may be notified of changes. | Back to list |
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
Sep 13, 2012
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
(No comment was entered for this change.)
Status:
NoFix
|