Python-插入ms访问表 [英] Python - insert into ms access table

查看:77
本文介绍了Python-插入ms访问表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过某些查询从ms访问中获取一些数据,但是我无法将数据存储到任何表中,例如:

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)

我的数据库中确实有"people"表...

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

我不知道这个输出是否有用:

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

线程'MainThread'(0x30e4)已退出,代码为0(0x0).

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

程序'[9696] python.exe'已退出,代码为0(0x0).

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

感谢您的帮助,

瓦茨拉夫

推荐答案

您忘记提交更改.

添加

connection.commit() 

到代码末尾.

这篇关于Python-插入ms访问表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆