简体   繁体   中英

I am unable to write to MS Access Database using pyodbc

I am unable to write this df into the access table. What am I not doing right?

conn_str = (
    r'DRIVER={Microsoft Access Driver (*.mdb)};'
    r'DBQ=C:\Users\harsh\Desktop\Database1.mdb;'
)
cnxn = pyodbc.connect(conn_str)
SQL = 'SELECT * FROM Index_data;'
dfins = pd.read_sql(SQL, cnxn)
for index, row in dfins.iterrows():
    with cnxn.cursor() as crsr:
        crsr.execute('select * from df')
conn.commit()

找不到错误数据源

You probably have not installed ODBC driver for MS Access, or its name

"Microsoft Access Driver (*.mdb)"

don't agree with the string used in your program — for newer versions of Microsoft Access it is

"Microsoft Access Driver (*.mdb, *.accdb)" .

So verify its name, or install it:

  1. Open Control Panel , select Administrative Tools , then ODBC Data Sources .

  2. New window will open up. Select “User DSN” tab.

Then verify the driver name, or install an appropriate Microsoft Access Driver — see for example Steps to create a New ODBC Connection on Windows 10 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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