xADO For CW Online Documentation

Properties

Property Name Set Get
ConnectionString Build a ConnectionString using ADO syntax. After connecting, this property contains the full ADO ConnectionString.
ConnectionTimeout Set how long to wait for a connection (seconds). Return connection wait value.
CommandTimeout Set how long to wait for a command to execute (seconds). Return command wait value.
ErrValue (Read Only) Returns last error number. Error 0 means that method was successful. Valid only after Methods are called.
ErrString (Read Only) Descriptive Error Message. Valid only after reading ErrorValue above.
SQL Valid SQL syntax. Can be SELECT,UPDATE,DELETE, or any other valid SQL statement for the connected data provider. Last SQL statement.
RecordCount (Read Only) Returns Number of Records Available After Exec Method.
FieldCount (Read Only) Returns Number Of Fields After Exec Method.
FieldIndex Field Number To Query (Zero Based Index). Current Field Number
FieldName (Read Only) Returns Field Name (Based on FieldIndex).
FieldName (Read Only) Returns Field Name (Based on FieldIndex).
FieldType (Read Only) Returns Field Type Equate (Based on FieldIndex).
FieldSize (Read Only) Returns Field Size (Based on FieldIndex).
FieldValue (Read Only) Returns Field Value (Based on FieldIndex).

Methods

Method Description Requirements
Connect Connects To Datasource. ConnectionString Must be Set To A Valid ADO Connection String. Check The ErrValue Property After Calling This Method.
Disconnect Disconnects From Datasource. A Valid Connction Must Exist.
Exec Executes The SQL Property. The SQL Property Must Be Set To A Valid SQL Statement. Check The ErrValue Property After Calling This Method.
GetField Loads Field Values. The FieldIndex Property Must Be Set To A Valid Field Number.
MoveNext Moves To The Next Record. Always Check The ErrValue Propery After Calling This Method.

Setting Properties, Getting Properties, and Calling Methods From CW
Assume that the control equate for the OCX control is ?DB
Set Property ?DB{'SQL'}='SELECT * FROM Table'
Get Property LOC:VARIABLE=?DB{'SQL'}
Call Method ?DB{'Exec'}

Connection Sample Source Code
      ?db{'ConnectionString'}='Provider=Microsoft.Jet.OLEDB.3.51;Data Source=Nwind.mdb'  !set connect string - see ADO documentation
      ?db{'Connect'}                           !call Connect Method
      if ?db{'ErrValue'}<>0 then               !if Connect Error display error message
        message(?db{'errstring'})
	  end

Exec Sample Source Code
      ?db{'sql'}='SELECT * FROM Customers'     !set SQL string (Usuall a SELECT)
      ?db{'Exec'}                              !call Exec Method
      if ?db{'ErrValue'}<>0 then               !If SQL syntax error show error message and try again
        message('Exec='&?db{'errstring'})
        return(level:benign)
      end
      free(qF)
      loc:format=''
      loop i#=0 to ?db{'FieldCount'}           !loop through returned field descriptions
        ?db{'fieldindex'}=i#                   !set field to look at (zero based indexing)
        ?db{'Getfield'}                        !call Getfield method to populate field info
        qF:FieldName=?db{'FieldName'}          !save Field Name
        qF:FieldType=?db{'FieldType'}          !save Field Type (See ADO documentation for equates)
        qF:FieldSize=?db{'FieldSize'}          !save field size
        add(qF)
        if i#<10 then loc:format="clip(loc:format)" & '80L(2)|M~' & clip(qf:fieldName) & '~@s30@' !create format string for data list box end end display ?list2{prop:format}="clip(loc:format)" ?progress1{prop:RangeHigh}="?db{'RecordCount'}" !set progrss bar with the number of records returned unhide(?progress1) free(qD) p#="0" loop p#+="1" if p#>1000 then                               !stop at 1000 records just in case
          message('Max Records of 1000 Reached')
          break
        end
        ?progress1{prop:progress}=p#
        display(?progress1)
        loop i#=0 to ?db{'FieldCount'}                !loop through fields to get data
          if i#>9 then break.                         !stop at 10 fields for list box
          ?db{'fieldindex'}=i#                        !set field to get value from
          ?db{'Getfield'}                             !call Getfield method to populate field info
          qd:sField[i#+1]=?db{'fieldValue'}           !save field value (this is the data in the field)
        end                                           !  you can convert dates to CW dates with the deformat command
        add(qD)
        ?db{'MoveNext'}                               !get next record
        if ?db{'Errvalue'}<>0 then                    !check for error (usually EOF for end of data)
          break
        end
      end