Show/Hide Toolbars

Xs2Ado Help

Navigation: Examples > RecordSet

RecordSet 2: Fields collection

Scroll Prev Top Next More

The sample below uses the fields collection to get the data from a recordset.

There is no real benefit here, except that the fields collection also allows you to access the other properties of the columns of the result set, such as type, length etc.

 

FUNCTION Start

 LOCAL oConn AS AdoConnection

 LOCAL uError        AS USUAL

 LOCAL cbErr AS CODEBLOCK

 LOCAL oRs AS AdoRecordSet

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

 BEGIN SEQUENCE

 oConn := OpenConnection()

 ? "Open a STATIC cursor with Pessimistic Locking and a table name"

 ? "Get data through Fields Collection on RecordSet"

 

 oRs := AdoRecordSet{}

 oRs:Open("Employee",oConn, AdOpenStatic, AdLockpessimistic, AdCmdTable)

 ? "Number of rows in resultset: ",oRs:RecordCount , oRs:Source

 wait

 DO WHILE .NOT. oRs:EOF .and. oRs:AbsolutePosition < 20

         // show 'record number' and column values

         // using the Fields Collection

         ? oRs:AbsolutePosition,oRs:FIELDs:[Item, "Emp_Id"]:Value, ;

         oRs:FIELDs:[Item, "LName"]:value

         oRs:MoveNext()

 ENDDO

 oRs:close()

 oConn:Close()

 

 

 RECOVER USING uError

 ? uError:description

 END

 wait

 ErrorBlock(cbErr)

 

 RETURN