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 ORDER BY LASTNAME"
  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"
  msg = "Student names:"& Chr(10)
  result.FirstRow
  firstName = result.GetValue("FIRSTNAME", firstName)
  lastName = result.GetValue("LASTNAME", lastName)
  msg = msg & Chr(10) & firstName & " " & lastName
  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
テーブルを作成するアクションでは、テーブルの作成方法、削除方法、テーブルへの行の追加方法を示します。行を追加するアクションでは、テーブルへの行の追加方法を示します。行を削除するアクションでは、行を検索しテーブルから削除する方法を示します。
Uselsx "*LSXODBC"
%INCLUDE "lsconst.lss"
Dim session As NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Sub Postopen(Source As Notesuiview)
  Set session = New NotesSession
  Set db = session.CurrentDatabase
  Set view = db.GetView("Phone book")
End Sub
Sub Click(Source As Button)
REM Create new table
  Dim con As New ODBCConnection
  Dim qry As New ODBCQuery
  Dim result As New ODBCResultSet
  Set qry.Connection = con
  Set result.Query = qry
  con.ConnectTo("ATDB")
  qry.SQL = "CREATE TABLE Phone (LASTNAME CHAR(32), " & _
  "FIRSTNAME CHAR(32), PHONENO CHAR(16))"
  result.Execute
  If qry.GetError <> DBstsSUCCESS And _
  Mid$(qry.GetExtendedErrorMessage, 31, 19) = _
  "File already exists" Then
    If Messagebox _
    ("Do you want to delete the existing table?", _
    MB_YESNO, "Table already exists") = IDYES Then
      result.Close(DB_CLOSE)
      qry.SQL = "DROP TABLE Phone"
      If Not result.Execute() Then
        Messagebox "Couldn't drop",, "Error"
        con.Disconnect
        Exit Sub
      End If
      result.Close(DB_CLOSE)
      qry.SQL = _
      "CREATE TABLE Phone (LASTNAME CHAR(32), " & _
      "FIRSTNAME CHAR(32), PHONENO CHAR(16))"
      result.Execute
    Else
      result.Close(DB_CLOSE)
      con.Disconnect
      Exit Sub
    End If
  End If
  If qry.GetError <> DBstsSUCCESS Then
    result.Close(DB_CLOSE)
    con.Disconnect
    Messagebox qry.GetExtendedErrorMessage,, _
    qry.GetErrorMessage
    Exit Sub
  End If
  result.Close(DB_CLOSE)
  qry.SQL = "SELECT * FROM Phone"
  result.Execute
  Set doc = view.GetFirstDocument
  While Not(doc Is Nothing)
    result.AddRow
    Call result.SetValue("LASTNAME", doc.lastName(0))
    Call result.SetValue("FIRSTNAME", _
    doc.firstName(0))
    Call result.SetValue("PHONENO", _
    doc.phoneNumber(0))
    result.UpdateRow
    Set doc = view.GetNextDocument(doc)
  Wend
  result.Close(DB_CLOSE)
  con.Disconnect
End Sub
Sub Click(Source As Button)
REM Add new row(s)
  Dim con As New ODBCConnection
  Dim qry As New ODBCQuery
  Dim result As New ODBCResultSet
  Set qry.Connection = con
  Set result.Query = qry
  con.ConnectTo("ATDB")
  qry.SQL = "SELECT * FROM Phone"
  result.Execute
  Set dc = db.UnprocessedDocuments
  Set doc = dc.GetFirstdocument()
  If dc.Count = 0 Then
    result.Close(DB_CLOSE)
    con.Disconnect
    Exit Sub
  End If
  While Not(doc Is Nothing)
    result.AddRow
    Call result.SetValue("LASTNAME", doc.lastName(0))
    Call result.SetValue("FIRSTNAME", _
    doc.firstName(0))
    Call result.SetValue("PHONENO", _
    doc.phoneNumber(0))
    result.UpdateRow
    Set doc = dc.GetNextDocument(doc)
  Wend
  result.Close(DB_CLOSE)
  con.Disconnect
End Sub
Sub Click(Source As Button)
REM Delete row(s)
  Dim con As New ODBCConnection
  Dim qry As New ODBCQuery
  Dim result As New ODBCResultSet
  Set qry.Connection = con
  Set result.Query = qry
  con.ConnectTo("ATDB")
  qry.SQL = "SELECT * FROM Phone"
  result.Execute
  Set dc = db.UnprocessedDocuments
  If dc.Count = 0 Then
    result.Close(DB_CLOSE)
    con.Disconnect
    Exit Sub
  End If
  Set doc = dc.GetFirstDocument
  While Not(doc Is Nothing)
    If result.LocateRow(1, doc.lastName(0), _
    2, doc.firstName(0)) Then
      result.DeleteRow("Phone")
    End If
    Call doc.Remove(True)
    Set doc = dc.GetNextDocument(doc)
  Wend
  view.Refresh
  result.Close(DB_CLOSE)
  con.Disconnect
End Sub
Sub Click(Source As Button)
REM Display table
  Dim con As New ODBCConnection
  Dim qry As New ODBCQuery
  Dim result As New ODBCResultSet
  Set qry.Connection = con
  Set result.Query = qry
  con.ConnectTo("ATDB")
  qry.SQL = "SELECT * FROM Phone ORDER BY LASTNAME"
  result.Execute
  msg = "Phone entries:"& Chr(10)
  Do
    result.NextRow
    firstName = result.GetValue("FIRSTNAME", __
    firstName)
    lastName = result.GetValue("LASTNAME", lastName)
    phoneNo = result.GetValue("PHONENO", phoneNo)
    msg = msg & Chr(10) & firstName & " " _
    & lastName & " " & phoneNo
  Loop Until result.IsEndOfData
  Messagebox msg,, "Phone numbers"
  result.Close(DB_CLOSE)
  con.Disconnect
End Sub