简体   繁体   English

Python - 插入ms访问表

[英]Python - insert into ms access table

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: 我可以通过某些查询从ms访问中获取一些数据,但我无法将数据存储到任何表中,例如:

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). 线程'MainThread'(0x30e4)已退出,代码为0(0x0)。

The program '[9696] python.exe' has exited with code 0 (0x0). 程序'[9696] python.exe'已退出,代码为0(0x0)。

Thank you for your help, 谢谢您的帮助,

Vaclav 瓦茨拉夫

You forgot to commit your changes. 您忘了提交更改。

Add

connection.commit() 

to the end of your code. 到你的代码结束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM