How to use the triggers in .net application.how to call the triggers.I need the code.please help me as soon as possible.
You don't call a trigger from .NET....or any other programming language. Once you've written a trigger on your server, it's autonomous - that is - it runs itself.
Lets consider the following example:
- Create Trigger dbo.SetUserActive On dbo.Users
-
For Insert
-
As
-
Begin
-
-
/* Prevent calling applications getting erroneous notifications causing queries to incorrectly appear to fail by setting the NoCount parameter. */
-
Set NoCount On
-
-
Declare @Key int
-
-
Select @Key = User_PKey
-
From inserted
-
-
Update dbo.Users
-
Set User_Active = 1
-
Where User_PKey = @Key
-
-
Set NoCount Off
-
-
End
When I apply this trigger to my table, any time I insert a row into my Users table, the column User_Active will be set to 0, regardless of what I set it to in the insert query.
There is no way to call this trigger from code or from another query. It is attached to the Users table and runs autonomously. Hence, you can't call it from .NET or any other programming language. If you wish to have a function that you can call from .NET, then you need to look at Stored Procedures or User Defined Functions.