RecordSet 1: Collect access
<< Click to Display Table of Contents >> RecordSet 1: Collect access |
![]() ![]() ![]() |
This sample shows how to use a recordset. The connection is opened in the OpenConnection function.
The recordset is ForwardOnly, Readonly and uses the eof, absoluteposition and collect properties
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 Forwardonly, readonly cursor "
oRs := AdoRecordSet{}
//
oRs:Open("Select * from Employee",oConn, ;
adOpenForwardOnly, AdLockReadOnly, AdCmdText)
? "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 Collect access or the fieldget method
? oRs:AbsolutePosition,oRs:[Collect, "Emp_Id"], ;
oRs:FieldGet("LName")
oRs:MoveNext()
ENDDO
oRs:close()
oConn:Close()
RECOVER USING uError
? uError:description
END
wait
RETURN