Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Trigger fails from the VB application side

I have the following trigger created for a SQL Server 2000 table.

When I edit the data via the enterprise manager, the trigger executes successfully. However, from my VB application (using Adodc), it says,

"Row cannot be located for updating. Some values may have been changed since it was last read."

Any idea why this is happening please?

======================================================
CREATE TRIGGER [dbo].[trg_ins_update_inspection] ON [dbo].[tbl_ge_inspection]
FOR INSERT, UPDATE
AS

DECLARE @lng_id bigint
DECLARE @lng_clientid bigint
DECLARE @str_inspname nvarchar(20)
DECLARE @str_category nvarchar(20)
DECLARE @dte_mod_on datetime

DECLARE CurD cursor for select
lng_id ,
lng_clientid ,
str_inspname,
str_category
FROM inserted
open CurD

Fetch Next From CurD into
@lng_id ,
@lng_clientid ,
@str_inspname ,
@str_category

WHILE (@@FETCH_STATUS <> -1)
BEGIN
UPDATE dbo.web_tbl_reports SET str_category=@str_category, dte_mod_on = getdate() WHERE lng_clientid=@lng_clientid AND str_inspname = @str_inspname
Fetch Next From CurD into
@lng_id ,
@lng_clientid ,
@str_inspname,
@str_category
END

Close CurD
DEALLOCATE CurD

======================================================
[1448 byte] By [rkbnair] at [2007-11-11 9:43:23]
# 1 Re: Trigger fails from the VB application side
Try setting the recordset's Update Criteria property to adCriteriaKey:

Adodc1.Recordset.Properties("Update Criteria").Value = adCriteriaKey
Phil Weber at 2007-11-11 17:23:44 >
# 2 Re: Trigger fails from the VB application side
Should I use 'Update Criteria' itself. Or, should it be any field name?

I tried the code as is: but getting the same error again.
rkbnair at 2007-11-11 17:24:51 >
# 3 Re: Trigger fails from the VB application side
Update Criteria is not a field name, it's a property of the ADO recordset object. If setting that property doesn't help, try adding SET NOCOUNT ON to your trigger.
Phil Weber at 2007-11-11 17:25:50 >
# 4 Re: Trigger fails from the VB application side
Phil,

I added SET NOCOUNT ON.

It works now.

BTW, what does 'SET NOCOUNT ON' do?
rkbnair at 2007-11-11 17:26:55 >
# 5 Re: Trigger fails from the VB application side
Hmm, where would one go to find that out? ;-)
Phil Weber at 2007-11-11 17:27:54 >