WPF live Update from database

随声附和 提交于 2019-12-13 18:15:29

问题


I am building a multiuser WPF application (requirement is a desktop app), database SQL Server 2008.

There are two types of users.

The first type user will enter a record which would be stored in a table.

The second type user initially will be presented with a listbox with the records from the table. The requirement is that the listbox must be updated live (i.e. if a new record is entered by the first user the listbox must be updated).

Currently I have not yet implemented the Database functionality. I am currently working with ObservableCollection and simulating this scenario.

I would like to know the best approach for achieving this. Should i use a timer and keep querying the table? Is there a more efficient way? Is this even possible (should I switch to ASP.NET?) ?

I would appreciate any suggestions and tips that you may have.


回答1:


Try using SqlDependency, since it can raise an event (OnChange) in your code when the results of a query would change on the server (as the result of an INSERT or UPDATE from another user or process, for example)

An example of its use on CodeProject for a simple live chat application:

http://www.codeproject.com/KB/database/chatter.aspx



来源:https://stackoverflow.com/questions/5009036/wpf-live-update-from-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!