Calling trigger in c#

Posted by satender2008-12857 under C# on 12/6/2011 | Points: 10 | Views : 5633 | Status : [Member] | Replies : 5
Hi,

Suppose i have wrote a trigger like this :-

CREATE TABLE Orders (Ord_ID int IDENTITY, Ord_Priority varchar(10))
go
CREATE TRIGGER tr_Orders_INSERT
ON Orders
FOR INSERT
AS
IF (SELECT COUNT(*) FROM inserted WHERE Ord_Priority = 'High') = 1
BEGIN
PRINT 'Email Code Goes Here'
END
go
INSERT Orders (Ord_Priority) VALUES ('High')

-------------------result------------

Email Code Goes Here

Now i want to call this trigger on Button_Click event in c# window page.

????????????

Thanks in advance.

Satender.




Responses

Posted by: Sksingh on: 12/6/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Satender,

First of all triggers get fire automatically whenever any operation (insert,delete,update) does on particular table for which trigger has been created .
For your case as you have created a trigger on order table for insert.
So whenever you insert a data in order table as simple you do for normal insertion your trigger will get fire automatically..

For practical example for trigger , you can just modify your trigger as instead of print , insert some dummy data to any other table. You can come to know about its functionality clearly..


Regards,
Sunil

satender2008-12857, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: satender2008-12857 on: 12/6/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Sunil,

Thanku so much, i got it.

Thanks again...

Regards,
Satender

satender2008-12857, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/13/2012 [Member] Bronze | Points: 25

Up
0
Down
A trigger is a pl/sql block structure which is fired when a DML statements like Insert, Delete, Update is executed on a database table. A trigger is triggered automatically when an associated DML statement is executed.

Syntax of Triggers

The Syntax for creating a trigger is:

CREATE [OR REPLACE ] TRIGGER trigger_name

{BEFORE | AFTER | INSTEAD OF }

{INSERT [OR] | UPDATE [OR] | DELETE}

[OF col_name]

ON table_name

[REFERENCING OLD AS o NEW AS n]

[FOR EACH ROW]

WHEN (condition)

BEGIN

--- sql statements

END;

SQL Server 2000 has many types of triggers:

1. After Trigger
2. Multiple After Triggers
3.Instead Of Triggers
4. Mixing Triggers Type

satender2008-12857, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/13/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Satender,
If you got answer then u can mark as answer.

Thanks & Regards
Hari

satender2008-12857, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/14/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi Satender,
Please Mark as Answer if it helpful to you..That helps others who search the same...

satender2008-12857, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response