Updating table in sql server

Hello,

I have following code in an agent which connects SQL Server database.

This is what it should do,

  1. Select all the records from a table where VPOSTS = “”

  2. Then create the lotus notes document and then stamp an appropriate record in SQL Server with status = “OPEN”

Question

The same code works fine in for AS400 connection. But in SQL Server it only stamps the last record. Any idea why?

Thanks in Advance

Urit

Option Public

Uselsx “*LSXODBC”

%INCLUDE “lserr.lss”

%INCLUDE “lsxbeerr.lss”

Dim db As NotesDatabase

Dim errnum As Integer

Dim con As ODBCConnection

Dim qry As ODBCQuery

Dim result As ODBCResultSet

Dim msg As String

Dim username As String, password As String, temp As String, loopcount As Long

Sub Initialize

Dim session As New NotesSession

.

.

.

.

temp = con.ConnectTo("TEST", "", "")

qry.SQL = "SELECT * from dbo.tbl1 where tbl1.VPOSTS = ''"



If Not con.IsConnected Then

	Messagebox con.GetExtendedErrorMessage,, _

	con.GetErrorMessage

	Exit Sub

End If

If Not result.Execute Then

	Messagebox result.GetExtendedErrorMessage,, result.GetErrorMessage

	Exit Sub

End If



REM Display result set properties after Execute





Set db = session.CurrentDatabase

Set oview = db.GetView("ocomp")





Do

	loopcount = 0

	Print "Updating Summary Record " & loopcount + 1

	Print "Please wait..."

	result.NextRow

	

	key = Trim(result.getvalue("vpopo#"))



	Set doc = oview.GetDocumentByKey( key, True )

	

	If Not doc Is Nothing  Then

		

		oStatus = Ucase$(doc.oStatus(0))

		

		Call result.SetValue("POSTS", PoStatus) ' Which will be OPEN

		result.UpdateRow		

		

		

	End If		

	

	loopcount = loopcount +1

Loop Until result.IsEndOfData





result.Close(DB_CLOSE)

con.Disconnect



Exit Sub