使用 Lotusscript 更新 sql 数据库

Update sql database using Lotusscript

我正在尝试通过 lotusscript 更新数据库的行。我的数据库连接运行良好。但是 result.update 命令不起作用,我的行没有被查询更新。问题出在查询 result.update 行中,因为它不会在其他任何地方出错。 任何人都有解决方案使其工作;

Option Public
Option Declare



UseLSX "*LSXODBC"

Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim dbcontacts As NotesDatabase

Dim doc As NotesDocument
Dim DocContact As NotesDocument

Dim CandidatView As NotesView
Dim ContactView As NotesView

Dim connection As ODBCConnection


Dim query As ODBCQuery
Dim result As ODBCResultSet


Dim consultantref As String

Set db = session.CurrentDatabase
Set connection = New ODBCConnection
Set dbcontacts= session.GetDatabase("", "names.nsf")


Set query = New ODBCQuery
Set result = New ODBCResultSet
Set query.Connection = connection
Set result.Query = query

On Error Resume Next

Set CandidatView=db.GetView( "Persons" )    
Set ContactView=dbcontacts.GetView( "(PersonsTestImport)" )

Call connection.ConnectTo("datasource", "username", "password")

If connection.IsConnected Then

    Set doc=CandidatView.GetFirstDocument
    CandidatView.AutoUpdate = False
    While Not ( doc Is Nothing )

        query.SQL="select * from users where id_toucan='"+doc.can_doc_ID(0)+"'"

         result.Execute

        If result.IsResultSetAvailable Then

            Do
                result.NextRow
                namepers=doc.can_pers(0)
                Set DocContact=ContactView.Getdocumentbykey(consultantref) 
                Call result.SetValue("first_name",DocContact.FirstName(0))
                Call result.SetValue("last_name", DocContact.LastName(0))       
                Call result.SetValue("email", DocContact.MailAddress(0))
                result.UpdateRow
            Loop Until result.IsEndOfData   
        End If

        Set doc = CandidatView.GetNextDocument( doc )
    Wend
Else

    MsgBox"Not connected"

End If
result.Close(DB_CLOSE)
connection.Disconnect

End Sub

我用 sql 查询 UPDATE 试过了,现在可以用了:

Option Public
Option Declare

UseLSX "*LSXODBC"

Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim dbcontacts As NotesDatabase

Dim doc As NotesDocument
Dim DocContact As NotesDocument

Dim CandidatView As NotesView
Dim ContactView As NotesView

Dim connection As ODBCConnection


Dim query As ODBCQuery
Dim result As ODBCResultSet


Dim consultantref As String

Set db = session.CurrentDatabase
Set connection = New ODBCConnection
Set dbcontacts= session.GetDatabase("", "names.nsf")


Set query = New ODBCQuery
Set result = New ODBCResultSet
Set query.Connection = connection
Set result.Query = query

On Error Resume Next

Set CandidatView=db.GetView( "Persons" )    
Set ContactView=dbcontacts.GetView( "(PersonsTestImport)" )

Call connection.ConnectTo("datasource", "username", "password")

If connection.IsConnected Then

Set doc=CandidatView.GetFirstDocument
CandidatView.AutoUpdate = False
While Not ( doc Is Nothing )
            namepers=doc.can_pers(0)
            Set DocContact=ContactView.Getdocumentbykey(consultantref) 

        Set DocContact=ContactView.Getdocumentbykey(consultantref)
        first_name_ref=DocContact.FirstName(0)
        last_name_ref=DocContact.LastName(0)
        email_ref=DocContact.MailAddress(0) 
        query.SQL="UPDATE users SET email_consult_ref='"+email_ref+"', first_name_consult_ref='"+first_name_ref+"',last_name_consult_ref='"+last_name_ref+"' where id_toucan='"+doc.can_doc_ID(0)+"'"

     result.Execute

    If result.IsResultSetAvailable Then

        Do
            result.NextRow
        Loop Until result.IsEndOfData   
    End If

    Set doc = CandidatView.GetNextDocument( doc )
Wend
End If
result.Close(DB_CLOSE)
connection.Disconnect

End Sub