Navigation:  Samples >

Dynaset sample

Previous pageReturn to chapter overviewNext page

This example creates a new dynaset-type Recordset object and opens it, appending it to the Recordsets collection in the default database. It then edits the record(s).

 

FUNCTION Start

LOCAL dbeng                AS DaoDBEngine

LOCAL dbsBiblio        AS DaoDatabase

LOCAL rstTitles        AS DaoRecordSet

LOCAL strSelect        AS STRING

LOCAL dDate                AS DaoDateTime

LOCAL cTitleId        AS STRING

LOCAL oBm                AS DaoBookMark

LOCAL oFldTitle        AS DaoField

LOCAL oFldDate        AS DaoField

Set color TO w+/b

cls

dbEng := DaoDbEngine{}

dbsBiblio := dbEng:OpenDatabase("\Vo2Jet\Northwind.mdb",NIL,NIL,NIL)

 

strSelect := "Select * From Titles Where Pub_Id = '1389' "

rstTitles := dbsBiblio:OpenRecordset(strSelect, dbOpenDynaset,NIL,NIL)

? "Dynaset sample"

IF (rstTitles:RecordCount > 0 .And. rstTitles:Updatable)

 oBm        := rstTitles:BookMark

 oFldTitle := rstTitles["Title_Id"]

 oFldDate  := rstTitles["Pubdate"]

 

 DO WHILE ! rstTitles:Eof

         rstTitles:EDIT()

 

         cTitleId := oFldTitle:Value

         dDate := oFldDate:Value

         // Note:

         // The next line generates a compiler warning

         // because Pubdate is no access or instance var

         //

         // At runtime this call is mapped to the NoIVarGet()

         // method, that maps this to the Collect access on

         // RecordSet

 

         ? "Before the change:", cTitleId, rstTitles:[Collect,"PubDate"]

         dDate:DateVal        := dDate:DateVal+31

         dDate:TimeVal        := dDate:TimeVal+120.0/86400

         oFldDate:Value        := dDate

         rstTitles:Update(NIL,NIL)

         ? "After the change: " ,cTitleId, rstTitles:[Collect,"Pubdate"]

         wait

         rstTitles:MoveNext()

 ENDDO

 rstTitles:BookMark        := oBm        

 ? "Bookmark restored, now at record :", oFldTitle:Value

   rstTitles:BookMark := rstTitles:LastModified

 ? "Bookmark of last modified record restored, now at record :", oFldTitle:Value

 rstTitles:Move(1,oBm)

 ? "First record after saved bookmark :", oFldTitle:Value

 wait

 //

 // Set datetime values to be returned as Date

 //

 DaoDateTimeAsDate(TRUE)

 ? "Now sort date in descending mode"

 rstTitles:Sort := "PubDate desc"

 rstTitles := rstTitles:OpenRecordSet(NIL,NIL)

 DO WHILE ! rstTitles:Eof

         // In the next line we use the Default collection

         // for a Recordset: the fields collection.

         // rstTitles["Title_Id"] returns the field object for

         // the Title_id column

     ? rstTitles:[Collect,"Pubdate"], rstTitles["Title_Id"]:Value

         rstTitles:MoveNext()

 ENDDO

 wait

ELSE

 ? "No such title or table not updatable"

ENDIF

dbsBiblio:Close()

 

wait