Access (MDB)

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)

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

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)
 * 1) read data using a select SQL statement
 * 2) we can use Tables[0] or Tables["t1"]


 * 1) execute stored procedure (named Access query)

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

con.Close