OLE Automation Example

Here’s a new example, which is using OLE Automation only (there’s no form with an OLE object on it).  This is an example of accessing data in another (ODBC) database:

 

% ADO (ActiveX Data Objects) Sample

PROCEDURE pAdoTest() Local(firstName)

  Let cn = $ObjCreate("ADODB.Connection")

  Let rs = $ObjCreate("ADODB.RecordSet")

  out 'Connecting to the database...'

  let v1=$objsetproperty(cn,"ConnectionString","DSN=AccessCustomers")

  let v1=$objsetproperty(cn,"CursorLocation",3)  % adUseClient

  let v1=$objrunmethod(cn,"Open")

  out 'Preparing RecordSet...'

  let v1=$objsetproperty(rs,"Source","Select * from Customers")

  let v1=$objsetproperty(rs,"ActiveConnection",cn)

  out 'Opening the recordset...'

  let v1=$objrunmethod(rs,"Open")

  

  out 'Returned records:'

  while $objgetproperty(rs, 'EOF') = 0

     Out $ttrim($objgetproperty(rs, 'Fields', 'FirstName'))

     Let vResult = $ObjRunMethod(rs, 'MoveNext')

  endwhile

  Let cn = $Null  

  Let rs = $Null

ENDPROCEDURE