Navigation:  Samples >

Recordset Sample

Previous pageReturn to chapter overviewNext page

This example creates a new Recordset object and opens it (thereby appending it to the Recordsets collection) in the default database. Then the example enumerates all the Recordset objects in the current database and all the fields in each Recordset object and closes the new Recordset. See the methods and properties in the Recordset summary topic for additional examples.

 

FUNCTION Start

LOCAL dbeng        AS DaoDBEngine

LOCAL db        AS DaoDatabase

LOCAL rstOrders        AS DaoRecordset

LOCAL rstCustomers        AS DaoRecordset

LOCAL rstTemp        AS DaoRecordSet

LOCAL tmpFld        AS DaoField

LOCAL nRs, nFld AS LONG

LOCAL oErr        AS USUAL

LOCAL cbOldErr AS CODEBLOCK

Set COlor TO w+/b

cls

BEGIN SEQUENCE

 cbOldErr := ErrorBlock({|oErr|_Break(oErr)})

 dbEng        := DaoDbengine{}

 

 

 // Open the database.

 db := dbEng:OpenDatabase("\VO2Jet\Northwind.mdb",NIL,NIL,NIL)

 

 // Open a Recordset.

 rstOrders                := db:OpenRecordset("Orders", dbOpenSnapshot,NIL,NIL)

 rstCustomers        := db:TableDefs:[Item,"Customers"]:OpenRecordSet(NIL,NIL)

 

 // Enumerate Recordsets.

 FOR nRS := 1 TO db:Recordsets:Count STEP 1

     rstTemp := db:Recordsets:[Item,nRS]

     ? "Recordset object: ", nRS, rstTemp:Name

 

     // Enumerate fields.

 

     ? "Fields: Name, Type, Value"

     FOR nFld := 1 TO rstTemp:Fields:Count STEP 1

         tmpFld := rstTemp:Fields:[Item,nFld]

         ? PadR(tmpFld:Name,15), PadR(DaoDataType(tmpFld:Type),15), tmpFld:Value

     NEXT

 NEXT

 db:Close()

RECOVER USING oErr

 Eval(cbOldErr,oErr)        

END

Wait