Why would result.AddRow sometimes fail?

I have an Lotusscript agent that updates an informix table. The agent looks to see if a particular record already exists on the table. If so, it updates it with new info. If it doesn’t exist, it adds a record with all the pertinent info. Problem is that result.AddRow doesn’t always work. It will go through and add 6 or 7 rows to the table, then the next time I do a Result.AddRow, it fails. So, consequently, the result.SetValue is resulting in an NSD, crashing my client. I can do error handling to code around it, but why would it fail?? It works OK sometimes!

Here’s a snippet of my code:

Sub updateTable

qry.SQL = "SELECT * FROM " & TBL_KNOWN & " WHERE DATE_ID=" & dts(z) & "'"

If Not res.execute Then

	Print "Error: " & res.GetExtendedErrorMessage,,res.GetErrorMessage 

	Exit Sub

End If

For w = 0 To 17

	res.FirstRow

	If res.LocateRow(EX_FLD_CAT_KS,dailyValues(w,0)) Then

		'do stuff

	Else

		'row not found, add it

		If res.AddRow Then

			Print "Row added OK"

		Else

			Print "Row not added"

		End If

		Call res.SetValue(EX_FLD_DATE_KS,dts(z))

		'The above is resulting in an NSD when the res.AddRow fails.

		'Why is res.AddRow failing?

	End If

Next

End Sub

Or alternatively, is there some way I can add code to tell me the reason for the failure?

Any help is greatly appreciated!

Subject: Why would result.AddRow sometimes fail?

You can’t keep calling AddRow without updating the added row back into the table, e.g. using UpdateRow. AddRow by itself does not insert any data into the database.

Use GetError and GetErrorMessage to find out why an operation failed.

It’s better to use the LC LSX for this kind of thing. It’s easier to get the original database error message in case of an error.

Subject: RE: Why would result.AddRow sometimes fail?

<You can’t keep calling AddRow without updating the added row back into the table, e.g. using UpdateRow. AddRow by itself does not insert any data into the database.>

My understanding was that I would do an addRow, then a SetValue, then an UpdateRow. I noticed my sample script doesn’t have the UpdateRow line - I tried to cut out all the extra stuff for this posting, but it is there. My problem is I often can’t even do the AddRow, let alone get to the UpdateRow part.

I’ll look into this. Thanks!

<It’s better to use the LC LSX for this kind of thing. It’s easier to get the original database error message in case of an error.>

I’m not sure what the LC LSX is. I’m pretty new to updating backend databases through script. I’ll look into this too. Thanks!