Server 2: Using Bookmarks with AdoServer
<< Click to Display Table of Contents >> Server 2: Using Bookmarks with AdoServer |
![]() ![]() ![]() |
Record numbers are not a valid record indicator in ADO, because they may change after the order of a resultset has been changed.
The advised alternative is to use Bookmarks in stead, as you can see in the sample below
FUNCTION Start
// this sample shows how to use the AdoServer object
LOCAL oConn AS AdoCOnnection
LOCAL oSrv AS AdoServer
LOCAL strCnn AS STRING
LOCAL oCons AS Console
LOCAL BM AS USUAL
oCOns := COnsole{}
strCnn := "Provider= SQLOLEDB;Initial Catalog=pubs; Data Source=(local);uid=sa;pwd=;"
// Set the default connection for better error reports
oCOnn := AdoConnection{}
AdoSetConnection(oConn)
oConn:Open(strCnn,NIL,NIL,NIL)
oConn:CursorLocation := AdUseClient
// Open a recordset USING a client Side, KeySet cursor
oCons:WriteLine("Open server, and set order to lastne, firstname after opening")
oSrv := AdoServer{"authors",oConn,adOpenKeySet, adLockOptimistic,adCmdTable)
oSrv:OrderBy("au_lname , au_Fname")
oCons:WriteLine("SHow first 20 rows")
DO WHILE ! oSrv:EOF .and. oSrv:RECNO < 10
oCOns:WriteLine(AsString( oSrv:RECNO)+" "+AsString(oSrv:FIELDGET(1))+ ;
" "+AsString(oSrv:FIELDGET(2)) +" "+oSrv:FIELDGET(3) )
// Save bookmark so we can navigate to the row later
BM := oSrv:Bookmark
oSrv:Skip(1)
ENDDO
oCons:Write("Press Enter")
oCons:Read()
oCons:WriteLine("Now change the order to Firstname, lastname")
oSrv:OrderBy("au_fname , au_lname")
DO WHILE ! oSrv:EOF .and. oSrv:RECNO < 10
oCOns:WriteLine(AsString( oSrv:RECNO)+" "+AsString(oSrv:FIELDGET(1))+ ;
" "+AsString(oSrv:FIELDGET(2)) +" "+oSrv:FIELDGET(3) )
oSrv:Skip(1)
ENDDO
oCons:Write("Press Enter")
oCOns:Read()
oCons:WriteLine("Skip back to last row of first list using bookmark")
oCons:WriteLine("Even though the record number has changed")
oSrv:Bookmark := BM
oCOns:WriteLine(AsString( oSrv:RECNO)+" "+AsString(oSrv:FIELDGET(1))+ ;
" "+AsString(oSrv:FIELDGET(2)) +" "+oSrv:FIELDGET(3) )
oSrv:Close()
oConn:Close()
oCons:Write("Press Enter")
oCOns:Read()