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
The action for creating a table demonstrates how to create a table, delete a table, and add rows to a table. The action for adding rows demonstrates how to add rows to a table. The action for deleting rows demonstrates how to locate and delete rows from a table.
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