External Exam Download Resources Web Applications Games Recycle Bin

Python with Microsoft Access

download Microsoft ODBC Driver 13 for SQL Server, 64 bit:



install ODBC Driver:



Open cmd.exe as administrator, type pip install pyodbc:



put access database somewhere easy to find:



change location string in python code to point to your database:

python.py

import pyodbc
driver = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};"

#change location string in python code to point to your database:
location = "DBQ=C:\\access\\shop.accdb"

connection = pyodbc.connect(driver + location)
cursor = connection.cursor() #for traversal of records
resultSet = cursor.execute("SELECT * FROM customers")
for row in resultSet:
    print(row.firstName)
cursor.close()
connection.close()

run in IDLE or favourite IDE: