ODBCLINK/SE Reference Manual (36217-90410)

Using ODBCLink/SE With ODBC Applications ODBCLink/SE Reference Manual
ODBCLink/SE
54 ©M.B. Foster Associates Limited 1995-2000
Connecting with ADO’s
1. DECLARE YOUR VARIABLES FOR THE CONNECTION
2. SET THE CONNECTION STRING
3. SET AND OPEN THE CONNECTION TO THE DATABASE/TABLE
4. SET AND OPEN THE RECORDSET FOR THE TABLE
5. USE THE RECORDSET INFORMATION YOU NEED AND PROCESS IT ACCORDINGLY
6. MAKE SURE YOU CLOSE ANY ODJECTS THAT YOU HAVE CREATED
WHEN ERRORS OCCUR(OR WHEN EXITING)
1 Dim ADORS As ADODB.Recordset
Dim ADOCN As ADODB.Connection
Dim strConnect As String
2 strConnect = "DSN=YOURDSN;UID=YOURUID;PWD=YOURPWD;"
3 Set ADOCN = New ADODB.Connection
'Set cursor for the client or server end
ADOCN.CursorLocation = adUseClient
'Open Connection
ADOCN.Open strConnect
4 'Open the Recordset
Set ADORS = New ADODB.Recordset
With ADORS
'Set the cursor type to be used with the recordset
.CursorType = adOpenForwardOnly
.LockType = adLockReadOnly
'Open the recordset with query, connection
.Open "SELECT * FROM TABLE", strConnect
End With
5 While Not ADORS.EOF
' Insert your query processing code here.
ADORS.MoveNext
Wend
6 'close objects and set to nothing
ADORS.Close
ADOCN.Close
Set ADORS = Nothing
Set ADOCN = Nothing
End Sub