Examples: Query property

This example sets up the necessary query connections in the Postopen script of a form. The Connection property of ODBCQuery must specify an ODBCConnection object. The Query property of ODBCResultSet must specify the ODBCQuery object.

Uselsx "*LSXODBC"
Dim con As ODBCConnection
Dim qry As ODBCQuery
Dim result As ODBCResultSet

Sub Postopen(Source As Notesuidocument)
  Set con = New ODBCConnection
  Set qry = New ODBCQuery
  Set result = New ODBCResultSet
  Set qry.Connection = con
  Set result.Query = qry
End Sub

Sub Click(Source As Button)
  Dim firstName As String
  Dim lastName As String
  Dim msg As String
  con.ConnectTo("ATDB")
  qry.SQL = "SELECT * FROM STUDENTS"
  result.Execute
  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"
  result.Close(DB_CLOSE)
  con.Disconnect
End Sub