Python - insert into ms access table

久未见 提交于 2019-12-10 19:48:44

问题


I am able get some data from the ms access by some query, but I am not able to store data into any table, for example:

import sys, os, pyodbc

conn_str = (
    r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
    r'DBQ=C:/Users/vlcek/Desktop/pokusdb.accdb;'
    )
connection = pyodbc.connect(conn_str)


cursor = connection.cursor()

sql="Insert into people (user_id, Name, Surname) values (27, 'Peter','Jackson')"

cursor.execute(sql)

I do have the table "people" already in database...

I am getting this output, I don't know, if it relevant:

The thread 'MainThread' (0x30e4) has exited with code 0 (0x0).

The program '[9696] python.exe' has exited with code 0 (0x0).

Thank you for your help,

Vaclav


回答1:


You forgot to commit your changes.

Add

connection.commit() 

to the end of your code.



来源:https://stackoverflow.com/questions/51976146/python-insert-into-ms-access-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!