SqlCommand cmd = new SqlCommand(); cmd.CommandText = "select id from dbo.table"; // Only one column! cmd.CommandType = CommandType.Text; SqlDependency d = new SqlDependency( cmd ); d.OnChange += new OnChangeEventHandler(dependency_OnChange); I change the value of any field in table , dependency_OnChange is Excute. I just want when id changed,dependency_OnChange is Excute
Moved byBob BeaucheminMVP, AnswererFriday, October 30, 2009 4:38 AMMoved to a more appropriate group (From:.NET Framework inside SQL Server)
That is the only way that SqlDependency works. There is no way to change this behavior. Any field change will fire the dependency and the dependency message does not specify which column or rows have changed.
Just as Bob said, any filed change will fire the denpendency. In you case, I think you need to use trigger instead, when the table got updated, you need to check the origial value and the update value mannually, and try to fire some relevant event you defined.
Thanks.Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.