.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

How can I use triggers ?

Posted By:      Posted Date: September 07, 2010    Points: 0   Category :ASP.Net
I have a Database with some tables in an Asp.Net project (C#),I wanna to run a method in C# whenever some data was written in the tables. I know I have to use triggers, but I don't know how!!!It would be appreciated if you guide me. P.S:I'm using SQLExpress 2008,

View Complete Post

More Related Resource Links

Data Points: Disabling Constraints and Triggers


What to do when you need to disable triggers and constraints to perform data synchronization and other tasks with an offline database.

John Papa

MSDN Magazine April 2007

Can I use TCP sockets within managed funcs, triggers and stored procedures?

I have seen nothing prohibiting this, but have not yet had time to write some test code. Does anyone know for sure if SQL Server 2008 prohibits or allows TCP sockets for communications, inside a C# SQL/CLR function or method? I guess it must because this is implict when creating data connections and so on, which are obvioulsy allowed. Thanks Cap'n  

I have 3 triggers defined on an sqlserver2008 table and I can't find them with c#

I've got the code below and when I run it, it always says there are 0 triggers in table.Triggers.  I added some debugging code checkin the table.HasDeleteTrigger, etc. and from that, I get the exception: "To accomplish this action, set property HasDeleteTrigger." when I try to set it to bool hasDeleteTrigger. I can get stored procedures find, just not triggers. Below is my problem code: foreach (Database database in databaseCollection) { if (database.Name.Equals(catalogName)) { // first we need to delete triggers associated with all tables that begin // with our prefix. we can skip our the framework tables because those // don't have triggers on them // grab all tables, filter for non prefixed ones in foreach loop so we can delete triggers from non prefixed ones results.AddRange(from Table table in database.Tables select table.Name); foreach (var tableName in results) { var table = new Table(database, tableName, CrSyncDbSchemaName); table.Refresh(); bool hasDeleteTrigger = table.HasDeleteTrigger; bool hasAfterTrigger = table.HasAfterTrigger; bool hasInsertTrigger = table.HasInsertTrigger;



Triggers when Log-Shipping is used

When we restore a db using Log-shipping, do the triggers in the destination db get fired from the changes occured in the shipped log? I guess the answer is negative but just want to make sure I am not missing anything. Thanks in Advance.  

Update Panels, Postback Triggers, and GridViews, Oh my

I've been battling with this page for the past couple days and it works, but it's annoying, so I am hoping someone maybe has dealt with this and can help me a little.   I have an UpdatePanel that acts as a container for a number of other update panels, everything in this container works.  I got the bright idea to add a ModalPopup Extender to enhance the user experience a little when performing a certain function on the site.  The panel that acts as the container for the ModalPopup sits outside the UpdatePanel Container because if it's in the container, any interaction with a child control throws "Input string not in the correct format" error message.  Because this is outside the comfort of the UpdatePanel Container, any control that populates information into the Popup control has to register a Postback.  Thus my problem: the controls that populate the Popup are GridViews.  The only GridView Event I care to cause a PostBack is the SelectedIndexChanged, but PostBack Triggers don't care, they take all comers.  Want to go to the next page? PostBack. Sort? Hell Yeah, Postback. My initial solution is to provide a confirm type of a message under the gridview and have the user confirm their selection by clicking a button to avoid causing a postback until it's necessary, but you know what? That kinda sucks, so I sub

EventHandler triggers another EventHandler

I have two EventHandlers - A and B. EventHandler A populates items in Child list, when Parent list creates a new item. Or vise versa, deletes items in Child list when Parent list deletes an item. There is a ParentID in Child list to refer back to ID column in Parent list. EventHandler B duplicates items from Site 1 to Site 2. i.e. creates a new item in Child list of Site 2, when Site 1 creates a new item in Child list. Or vise versa, deletes item in Child list in Site 2 when Site 1 deletes an item in Child list. The two Child lists are almost identical except Site 2 Child list has SourceID pointing back to ID column in Site 1 Child list ID field.   Site 1                                      Site 2 Parent    | EventHandler A    V Child   --- EventHandler B --->  Child   Now if I create/delete item in Parent list of Site 1, Child list of Site 2 will be affected, thanks to EventHandler A and B. Here A triggers B. If I create/delete item in Child list of Site 1, Child list of Site 2 will be affected as well, here only EventHandler B is triggered. My question is: Is there anyway to tell in EventHandler B, that it is triggered originally from Parent lis

Real Time Stored Procedures and Triggers..

hi ..I am learning  Dot Net and i am looking for a job  in it these days... Every Company looked   if am mainly good in Writing Real Time Stored Procedures and Triggers... I am able to grab the basic concepts , but am not able  to write real time examples.... Kindly let me know some Websites or source  where i can find some real Times examples for  Stored Procedures and Triggers, coz  am interested in  practicing it ... Thanks in Advance...

Why does Output clause have the INTO requirement for tables with enabled triggers?


What is the reason for this restriction for Output clause?

If the OUTPUT clause is specified without also specifying the INTO keyword, the target of the DML operation cannot have any enabled trigger defined on it for the given DML action. For example, if the OUTPUT clause is defined in an UPDATE statement, the target table cannot have any enabled UPDATE triggers.

Implicit Transactions in Triggers


Here's my scenario:

First, I have two servers. In Server1 I have set up a Linked Server to Server2.

I have two databases on Server1. The first is the Customer database and the second is my Staging database. Server2 contains a database called Gateway.

I have AFTER INSERT, UPDATE triggers on tables in the Customer database that will insert records into tables in my Staging database.

The triggers on the tables in the Staging database will insert records into tables in the Gateway database on the Linked Server, Server2.

OK ... that is the setup. Now, the problem:

As you all probably know (and I didn't know until I started working with this), the statement in the Customer database that caused the trigger to fire, enlists everything in a transaction. If there is a problem several hops away with accessing the LinkedServer, then the entire thing is rolled back. IOW, the records in the table on the Customer database are never updated! This is bad (we can't mess with the functionality of our Customer's database, so our triggers there have to be fairly foolproof).

The trigger in the Customer database which INSERTS records into the Staging database should be ok and never fail (they are, after all, on the same Server). However, the trigger in the Staging database is where there could potentially be a problem if the LinkedServer is do

Update panal and triggers outside


I have a few buttons on a web page.

I have an update panel and I have 2 triggers that reference button 1 and 2 outside my update panel.

When I click on button 1  and 2 I want the update panel to "update" with content without a whole page refresh.

This seems simple enough but when I run I get the following error:

A control with ID 'btn1' could not be found for the trigger in UpdatePanel 'updateSomething'.

Here is my code.

<asp:button ID="btn1" Text="press me" Click="btn1_Click></asp:button>

<asp:button ID="btn2" Text="press me2" Click="btn2_Click></asp:button>

<asp:UpdatePanel ID="updateSomething" UpdateMode="Condtional" runat="server">
                    <asp:AsyncPostBackTrigger ControlID="btn1" runat="server"  EventName="Click" />

can Triggers in templates control multiproperty?


hi i wanto to control two properties value in a trigger. is it possible?

like that;

                        <Trigger         Property="IsEnable" Value="true"     
Property="IsReadOnly" Value="false" >
                            <Setter Property="MinHeight" Value="95" TargetName="DropDownBorder"/>

Get Values from last updated row using Sql server Triggers


I want to Get Values from last updated row using Sql server Triggers.

what is the procedure 4 that (equivalent to NEW and OLD keywords in Oracle).

Plz reply me

Thank You



Get Values from last updated row using Sql server Triggers


I want to Get Values from last updated row using Sql server Triggers.

what is the procedure 4 that (equivalent to NEW and OLD keywords in Oracle).

Plz reply me

Thank You


Adding triggers to a Merge Replicated published article in SQL Server 2008


Currently running merge replication on SQL Server 2008 10.0.1600 and I have a few questions around the correct procedures for adding and modifying triggers on published articles.  I've searched through the MSDN site and googled this but have not found any definitive information on correct procecdures.

1) When a new trigger is added to a published table do we just have to rerun the snapshot and then re-syncy the subscribers?  Just adding them does not seem to replicate them to subscribers.

2) When an existing trigger is modified should ALTER TRIGGER be used or should the trigger be dropped and then re-added?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend