SQL Server更改时需要刷新datagridview [英] Need to refresh datagridview when SQL server changes

查看:95
本文介绍了SQL Server更改时需要刷新datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个为我的工作创建的VB.Net应用程序。它在多个用户PC上运行,并使用Access数据库进行数据存储,每隔5分钟使用一个计时器刷新DataGridView,以使每个人都保持最新状态。现在我正在切换到SQL Server Express 2014,我听说它有标志更改的触发器。我想知道的是,如果我可以使用这些而不是计时器,只要在SQL Server表中更改了某些内容,就会触发对DataGridView的更新?任何VB.Net或SQL代码示例将不胜感激。感谢您的帮助!



我的尝试:



有尝试谷歌搜索SQL Server触发器,但没有任何意义。

I have a VB.Net application that I created for my job. It runs on multiple users PC's and uses Access databases for data storage, with a timer to refresh the DataGridView every 5 minutes to keep everyone up-to-date. Now I'm switching over to SQL Server Express 2014 and I've heard that it has triggers that flag changes. What I'm wanting to know is if I can use these, instead of timers, to trigger an update to the DataGridView whenever something is changed in the SQL Server table? Any VB.Net or SQL code examples would be greatly appreciated. Thanks for any help!

What I have tried:

Have tried Google searches for SQL Server triggers, but nothing made sense.

推荐答案

我会说这可能是不可能的。插入,更新或删除某些内容时,Sql server会触发,但是通过与vb项目对话的任何内容都无法公开。唯一的想法是我可以建议在每个表上有一个rowguid和一个修改日期,并在一个计时器上,去检查rowguid。如果不同,则重新加载数据,小心不要覆盖本地用户所做的更改。



如果多个用户在访问数据库中(仅使用访问表单和网格),那么从一个用户以某种方式(神奇地)更改将显示在其他表单和网格中。我没有看到任何对ado.net如此神奇的东西。如果我错了,请纠正我。
I'm going to say it is probably not possible. Sql server triggers fire when something is inserted, updated, or deleted, but that is not exposable through anything that would talk to your vb project. The only think I could suggest is to have a rowguid and a modified date on each table, and on a timer, go check the rowguid. If it is different, then reload your data, being careful to not overwrite changes the local user has made.

If multiple users are in an access database(using only access forms and grids), then somehow(magically) changes from one user show up in the others forms and grids. I have not seen anything so magical for ado.net. Please correct me if I'm wrong.


有一些方法可以以更改数据捕获和更改跟踪的形式跟踪SQL Server中的数据更改。你可以阅读它们。但是您正在寻找的解决方案可以使用SqlDependency实现。 CP中有几篇文章解释了如何使用它来获取有关更改的通知。



它可能不是您正在寻找的,但可以帮助您朝着正确的方向前进。



使用SqlDependency进行数据更改事件 [ ^ ]

使用SqlDependency和SqlCacheDependency查询通知 [ ^ ]
There are ways to track data changes in SQL Server, in the form of Change Data Capture and Change Tracking. You can read about them. But the solution you are looking for may be achieved using SqlDependency. There are a couple of articles in CP that explain how to use this for getting notification about changes.

It may not be exactly what you are looking for, but may help you go in the right direction.

Using SqlDependency for data change events[^]
Query Notification using SqlDependency and SqlCacheDependency[^]


这篇关于SQL Server更改时需要刷新datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆