本文介绍了如果数据库表更新/插入,如何获得Windows C#控件自动更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已经绑定到数据库(MySQL)表的listView WinForms-C#,但我似乎无法弄清楚当对数据库表进行更改时,如何使listView自动显示结果(update / insert),而用户不必触发事件,即button_click,timer_tick等...



有人可以指出我的方向正确。任何建议/解决方案将不胜感激!



谢谢,
-Donald

解决方案

SQL不支持将更改事件从数据库发送回客户端。



DataTable 不要发出数据库的更改。他们将变更信号发送到 DataTable 本身。



如果要查看实际数据库的更改,您有两个选择:


  1. 检测更改的简单方法是定期执行查询,每分钟或每5分钟一次,并检测更改数据库;


  2. 如果需要实时更改,替代方案是使用消息传递服务。您可以在更改数据库时实现向其发送信号的WCF服务。然后,其他进程(包括您自己的)可以使用回调接口连接到此WCF服务,并在发生这些更改时收到这些更改。这只有在您完全控制数据库更改后才有效。


第一个机制将为您定期更新像老POP3通知一样。第二种机制将为您提供实时更新。


I have a listView WinForms-C# that I've binded to a database (MySQL) table but I can't seem to figure out how to have the listView automatically display the results when changes are made to the database table (update/insert) without the user having to fire an event i.e. button_click, timer_tick, etc...

Can someone please point me in the right direction. Any advice/solutions would be greatly appreciated!

Thanks,-Donald

解决方案

SQL does not support sending change events back from the database to the client.

The events on the DataTable do not signal changes from the database. They signal changes to the DataTable itself.

If you want to see changes to the actual database, you have two choices:

  1. The simple way to detect changes is to periodically execute a query, say every minute or every 5 minutes, and detect changes to the database;

  2. If you require real time changes, the alternative is to have a messaging service. You could implement a WCF service to which you send a signal when you change the database. Then, other processes (including your own) can connect to this WCF service with a callback interface and receive these changes when they occur. This however only works if you have full control over changes to the database.

The first mechanism will give you periodic updates, like the old POP3 notifies. The second mechanism will give you real time updates.

这篇关于如果数据库表更新/插入,如何获得Windows C#控件自动更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 01:33