LOTUS CONNECTORS


Examples: Execute method
This agent executes an SQL query. The agent also displays some of the ODBCResultSet properties after the Execute method and after all the rows in the result set are accessed.

Uselsx "*LSXODBC"

Dim con As ODBCConnection
Dim qry As ODBCQuery
Dim result As ODBCResultSet
Dim firstName As String
Dim lastName As String
Dim msg As String

Sub Initialize
 Set con = New ODBCConnection
 Set qry = New ODBCQuery
 Set result = New ODBCResultSet
 Set qry.Connection = con
 Set result.Query = qry
 con.ConnectTo("ATDB")
 qry.SQL = "SELECT * FROM STUDENTS"
 If Not result.Execute Then
   Messagebox _
   result.GetExtendedErrorMessage,, result.GetErrorMessage
   Exit Sub
 End If
 REM Display result set properties after Execute
 Call DisplayResultSetProperties
 msg = "Student names:" & Chr(10)
 Do
   result.NextRow
   firstName = result.GetValue("FIRSTNAME", firstName)
   lastName = result.GetValue("LASTNAME", lastName)
   msg = msg & Chr(10) & firstName & " " & lastName
 Loop Until result.IsEndOfData
 Messagebox msg,, "Student Names"
 REM Display result set properties after  _
 REM processing result set
 Call DisplayResultSetProperties
 result.Close(DB_CLOSE)
 con.Disconnect
End Sub

Sub DisplayResultSetProperties
 If result.IsResultSetAvailable Then
   If result.NumRows = DB_ROWSUNKNOWN Then
     rows$ = "Not determined yet"
   Else
     rows$ = Cstr(result.NumRows)
   End If
   Messagebox _
   "NumColumns = " & result.NumColumns & Chr(10) & _
   "NumRows = " & rows$ & Chr(10) &  _
   "IsBeginOfData = " & result.IsBeginOfData & _
   Chr(10) & _
   "IsEndOfData = " & result.IsEndOfData & Chr(10) _
   & "CurrentRow = " & result.CurrentRow,,  _
   "Result set properties"
 Else
   Messagebox "Result set not available",, _
   "No result set"
 End If
End Sub

See Also