I have a Triggers in my table UpdateMRPRed(Insert/Update)
Code:
'--------------
'This is my code in SQL Server
'--------------
CREATE TRIGGER UpdateMRPRed ON dbo.mat_tblPurchaserequisitiondet
FOR UPDATE, INSERT
AS
UPDATE srv_tblMaterialsReqDet
SET srv_tblMaterialsReqDet.PRed = (SELECT SUM(QTY) FROM mat_tblPurchaserequisitiondet
WHERE MRNo = srv_tblMaterialsReqDet.MRNo AND StockCode = srv_tblMaterialsReqDet.StockCode)
WHERE (srv_tblMaterialsReqDet.StockCode = (SELECT TOP 1 StockCode FROM inserted))
AND (srv_tblMaterialsReqDet.MRNo = (SELECT TOP 1 MRNo FROM inserted))
'--------------
'This is my code in Visual Basic
'Scenario: In a master-detail form, recordset RSPurchReqDet is bound to a Datagrid (Detail) and is saved only after the master has been saved
'--------------
Dim i As Integer
With RSPurchReqDet
If Not .RecordCount = 0 Then
.MoveFirst
For i = 1 To .RecordCount
.Fields(0) = txtPRNo
On Error Resume Next
.UpdateBatch adAffectCurrent ' Error Occurs in this part on connectionstring based
.MoveNext
Next
On Error Resume Next
.UpdateBatch
ConnExec
End If
End With
---------------------------------------------------
Case:
If I manually input in SQL Server table, Trigger is OK
If I use a DSN ("DSN=Materials") for ADODB.Connection, Trigger is OK
If I use a Connectionstring for ("mConnStr=Provider.....") ADODB.Connection, Trigger Creates multiple copy of the row
Also
How do I add speed to my trigger? Takes atleast 5 seconds for a row to save with a trigger and less than a second for a row without the trigger. Is Speed the Cost of using Trigger (1 table has 3 triggers)???
Proud To Be Pinoy