str provider="Microsoft.Jet.OLEDB.4.0" ;;data provider for MS Access; part of Win2000 and later str datasource="$personal$\db1.mdb"; datasource.expandpath ;;MS Access database ($personal$ = My Documents) str sql="SELECT A, B FROM Sheet1" ;;select fields A and B from "Sheet1" table, all records
typelib ADODB {00000200-0000-0010-8000-00AA006D2EA4} 2.0 ;;the oldest version I've found on my computer
ADODB.Connection conn._create ;;connection object
conn.CursorLocation=ADODB.adUseClient ;;** str cc.format("Provider='%s';Data Source='%s';" provider datasource) ;;connection string
conn.Open(cc "" "" -1) ;;open without user/password ADODB.Recordset rs._create ;;*
rs.Open(sql conn ADODB.adOpenStatic ADODB.adLockBatchOptimistic ADODB.adCmdText) ;;execute SQL
rs.MarshalOptions=ADODB.adMarshalModifiedOnly ;;**
;IDispatch di; rs.ActiveConnection=di; conn.Close ;;use this to close connection and continue work with recordset
rep rs.RecordCount ;;for each record ,str s=rs.Fields.Item("A").Value ;;get value of field A ,out s ,rs.MoveNext ,
conn.Close ;;I think this is not necessary, although not documented
;* recordset object is used as container for the retrieved data; can contain multiple records (rows) and fields (columns)
;** not necessary if client and server is on same computer
;_____________________________
;ADO reference: search for "ActiveX Data Objects (ADO)" in http://msdn.microsoft.com/library/
;connection strings: http://www.carlprothman.net/Default.aspx?tabid=81
ADODB.Recordset rs._create str cc.format("Provider='%s';Data Source='%s';" provider datasource) ;;connection string
rs.Open(sql cc ADODB.adOpenStatic ADODB.adLockBatchOptimistic ADODB.adCmdText) ;;open connection and execute SQL
int r f for r 0 rs.RecordCount ;;for each record ,out "-- record %i --" r+1 ,for(f 0 rs.Fields.Count) out rs.Fields.Item(f).Value ;;display all fields ,rs.MoveNext
rs.Close ;;I think this is not necessary, although not documented
;Reads single record (row) from MS Access database db1.mdb table "Table1".
;Table structure: ID (string), A (long), B (string).
;Searches for ID="Hoonah" and retrieves whole record.
str datasource="$personal$\db1.mdb" ;;($personal$=My Documents) str table="Table1" str ID="Hoonah" str sql.format("SELECT * FROM %s WHERE ID='%s'" table ID)