Subject: DB2 with LotusNotes
First of all, you should read the Lotus Connectors section of the Designer Help file. It goes through everything I explain here. It is difficult to wrap your mind around the objects at first, but experimenting a bit yields good results.
The method I propose here is not the ODBC method you’re currently using. I did it this way because it’s much more efficient than ODBC and requires less setup. This is mentionned several times in the help files.
Dim nd As NotesDocument
Dim src As LCConnection
Set src = New LCConnection(“db2”)
src.Database = “XXXXXXXX”
src.UserID = “XXXXXX”
src.Password = “XXXXXXX”
src.Connect
Dim fl As New LCFieldList 'This is a logical representation of a record output
Dim key_fl As New LCFieldList(1,0) 'This object represents a key to give parameters to the select statement.
Dim keyfld As New LCField(LCTYPE_TEXT,1)
'You might not need these last 2 if you want to retrieve all the records in your DB2 table
'The LCField is the object where the data’s reference will be held
Dim myfld1 As New LCField (LCTYPE_TEXT, 1)
'If you want to retrieve Packed, Zoned, Numeric DB2 fields, use LCTYPE_NUMERIC
'If you want to use a key to retrieve only certain records
Set keyfld = key_fl.Append (“DB2_Fieldname”, LCTYPE_TEXT)
keyfld.Flags = LCFIELDF_KEY
keyfld.value = “Code900”
'This will get all records whose DB2_Fieldname field is equal to “Code900”
You can have multiple attributes to keyfld to do greater than, less than etc. The documentation explains the different key attributes.
'Then set a temporary variable to execute the search for those records
count=p_src.Select (Nothing, 1,fl)
'The fl Fieldlist object now points to the first row in the DB2 table.
Using a key to get rows, your instruction would look like
count=p_src.Select (key_fl, 1,fl)
'You don,t have to do the following, but it’s more efficient if you’re looping through many records
Set myfld1 = fl.Lookup (“DB2_Fieldname”)
'Now you have to actually fetch the data pointed to by fl
count = p_src.Fetch (fl, 1, 1)
'This retrieves the current row.If you execute this instruction many times in a row, it fetches the data for the next row each time.
'But looping through without doing anything with the data is kind of pointless, so before fetching again, do something with the data
Set nd= New NotesDocument
nd.form = “myform”
nd.mynotesfield = myfld1.text(0)
Call nd.Save(True,False)
I think from this you get a good idea how to go on by looping through successive fetches. I hope I didn’t just confuse you. Good luck,
Luc Millette