Okay, I think I got it figured out and found a pattern using SQL Server Profiler. This grid is ONLY running the UPDATE trigger, not the INSERT trigger. I assume this has something to do with the SELECT query coming from Table#1 and the INSERT/UPDATE queries going into Table#2.
SELECT query:
SELECT VendKey,VendID,VendName,CntctKey,PrimaryContactEmailAddr,Nickname,ContactGroup,BuyerKey,BuyerName,OwnerID,OwnerName FROM vdvVendorsEmailByBuyerAndOwner
INSERT query:
INSERT into custContact (CntctKey,CntctNickname,CntctGroup) Values ('@CntctKey','@Nickname','@ContactGroup')
UPDATE query:
UPDATE custContact set CntctNickname='@Nickname', CntctGroup='@ContactGroup' WHERE CntctKey='@CntctKey'
The only editable fields in the grid are Nickname and Contact Group. Those fields should be INSERTED or UPDATED with the Contact Key from Table#1 into Table#2. If those two fields were empty before editing, it MUST do an INSERT into Table#2 since there is no record to update in Table#2. However, the Grid is triggering the UPDATE query, so it fails (with no error in the Grid).
If one or both fields are already in the Grid, I'm able to edit the fields and when I click save it triggers the UPDATE query, as expected, and it updates the record in the database.
So the bottom line is how I have the grid built using Table#1 for the SELECT and Table#2 for for the INSERT/UPDATE, it will always fire the UPDATE query and never the INSERT.
My fix was to build a Stored Procedure in SQL and use that for the UPDATE query.
EXEC mmsInsertNickname '@CntctKey', '@Nickname', '@ContactGroup'
This Stored Procedure checks if the record exists and if it doesn't it inserts, if it does, it updates.
ALTER PROCEDURE [dbo].[mmsInsertNickname]
(
@CntctKey int,
@CntctNickname Varchar(100),
@CntctGroup Varchar(100)
)
AS
BEGIN
IF EXISTS (SELECT 1 FROM custContact
WHERE CntctKey=@CntctKey
)
BEGIN
UPDATE custContact set CntctNickname=@CntctNickname, CntctGroup=@CntctGroup
WHERE CntctKey=@CntctKey
END
ELSE
BEGIN
INSERT into custContact (CntctKey,CntctNickname,CntctGroup) Values (@CntctKey,@CntctNickname,@CntctGroup)
END
END
I struggled with this for many days. I was frustrated enough to start coding using a new control in ASP.NET, but now that this is resolved, I don't have to rebuild the entire thing.
I wish this was better documented so I didn't have to struggle with this.