Examples: ODBCQuery class

The following agent creates a query that retrieves all the rows in the STUDENTS table of the ATDB data source.

Uselsx "*LSXODBC"
Sub Initialize
  Dim con As New ODBCConnection
  Dim qry As New ODBCQuery
  Dim result As New ODBCResultSet
  Dim firstName As String
  Dim lastName As String
  Dim msg As String
  Set qry.Connection = con
  Set result.Query = qry
  con.ConnectTo("ATDB")
  qry.SQL = "SELECT * FROM STUDENTS"
  result.Execute
  msg = "Student names:" & Chr(10)
  If result.IsResultSetAvailable Then
    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"
    result.Close(DB_CLOSE)
  Else
    Messagebox "Cannot get result set for STUDENTS"
    Exit Sub
  End If
  con.Disconnect
End Sub