Can the SqlDataAdapter refresh itself when the tab

2019-08-06 10:53发布

问题:

My SQL Server table is updated from outside of my program (from a SQL trigger, actually), so the DataSet doesn't realize that there are changes and my DataGrid doesn't update unless I explicitly call SqlDataAdapter.Fill() again (e.g. with a "Refresh" button or a timed event).

Is there a way that ADO.NET can subscribe to change events or such so that it refreshes itself?

回答1:

Yes, using Query Notifications. You get a callback when the dataset has changed and you run your query again.