Thursday, May 04, 2006

SqlDependency in VS.NET 2005

SqlCommand command = new SqlCommand("Select * from Table");
// Clear any existing notifications
 command.Notification = null;
.
.
.
// Create the dependency for this command
 SqlDependency dependency = new SqlDependency(commmand);
 
// Add the event handler
dependency.OnChange += new OnChangeEventHandler(OnChange);




voidOnChange(object sender, SqlNotificationEventArgs e)
{
    SqlDependency dependency = sender as SqlDependency;
    dependency.OnChange += OnChange;
    //Handler for Object
    OnAnyEvent();
}

No comments: