Access (MDB)

From IronPython Cookbook

Example of connecting to Access database (using OLEDB)

import clr
import System
clr.AddReference("System.Data")

from System.Data import DataSet
from System.Data.OleDb import OleDbConnection, OleDbDataAdapter, OleDbCommand
from System.Data import CommandType

conStr = r'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\path\to\your.mdb;'
con = OleDbConnection(conStr)

# instead of tblTest use your own table name of course :-)
query = "SELECT * FROM tblTest"
adapter = OleDbDataAdapter(query, con)
ds = DataSet()
con.Open()
adapter.Fill(ds, "t1")

# read data using a select SQL statement
# we can use Tables[0] or Tables["t1"]
print '\ncolumn names:', ', '.join(str(x) for x in ds.Tables[0].Columns)
print '\n', ds.Tables[0].Rows.Count, 'rows of data:' 
for row in ds.Tables[0].Rows:
    print ', '.join(str(x) for x in row)

# execute stored procedure (named Access query)

query = "qryNameHere"
cmd = OleDbCommand(query, con)
cmd.CommandType = CommandType.StoredProcedure
cmd.ExecuteNonQuery()

con.Close()

TOOLBOX
LANGUAGES