Tuesday, October 20, 2009

Connect ODBC/Oracle Using LC coneector classes

Lotusscript code to connect ODBC/Oracle Using LC coneector classes



Sub Initialize
On Error Goto ErrorHandler

Dim session As New NotesSession
Dim LC_S As New LCSession
LC_S.clearstatus
Set LC_Conn = New LCConnection ("odbc2")

' Make a connection...
LC_Conn.Server = "lotussystem" ‘System DSN on server…
LC_Conn.UserID = "crystal" ‘SQL Server user id…
LC_Conn.Password = "crystal" ‘SQL Server password…
LC_Conn.Metadata = "employee" ‘SQL Server table name…
LC_Conn.Connect

Dim count As Integer
Dim lsQuery As String
Dim fldLst As New LCFieldList

' Execute the Query...
lsQuery = "Select * from employee"
count = LC_Conn. Execute (lsQuery, fldLst)

Dim fldLC As LCField

Dim fldFName As LCField
Set fldFName = fldLst.Lookup ("fname")
Dim fldLName As LCField
Set fldLName = fldLst.Lookup ("lname")

' Get the AppInfo view...
Dim loDb As NotesDatabase
Dim loVw As NotesView
Dim loAppInfoDoc As NotesDocument
Set loDb = session.CurrentDatabase
Set loVw = loDb.GetView("vwAppInfo")
Set loAppInfoDoc = loVw.GetFirstDocument

Call LC_Conn.Fetch (fldLst, 1, 1)
'Msgbox fldFName.Text(0)

loAppInfoDoc.count = "1"
loAppInfoDoc.EmpName = fldFName.Text(0) + " " + fldLName.Text(0)

Set fldLC = fldLst.Lookup ("emp_Id")
loAppInfoDoc.EmpID = fldLC.Text(0)

Set fldLC = fldLst.Lookup ("job_Id")
loAppInfoDoc.Job = Cstr(fldLC.Text(0))

Set fldLC = fldLst.Lookup ("hire_date")
loAppInfoDoc.Hire_Date = Cstr(fldLC.Text(0))

Call loAppInfoDoc.save(False, False)

' Disconnect the connection...
LC_Conn.Disconnect

CleanUp:
Exit Sub

ErrorHandler:
'Msgbox result.GetExtendedErrorMessage,, result.GetErrorMessage
Msgbox "An error has occurred in button at line no. " & Erl() & " and the error is " & Str$(Err) & " " & Error$
Resume CleanUp

End Sub

1 comment:

  1. This was helpful. I had, in the past, always used the ODBCConnection class instead of the LCConnection class. I didn't know you could do it this way. I prefer it because you can iterate through the names of the columns in a table without having to know their names.

    ReplyDelete

Search This Blog