如何刷新数据集以反映数据库的外部更改? [英] How to refresh a dataset to reflect external changes to the database?

查看:56
本文介绍了如何刷新数据集以反映数据库的外部更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WinForms应用程序中,该应用程序使用来自使用数据源配置向导"创建并连接到Access数据库的数据源的数据集.如何在运行时刷新数据集以反映外部发生的数据库更改(仅数据更改,无结构更改),而无需关闭并重新打开应用程序?

In a WinForms application that uses a dataset from a data source created using the Data Source Configuration Wizard and connected to an Access database. How can I refresh the dataset at run time to reflect changes (data changes only, no structural changes) to the database occurred outside without closing and reopening my application?

提前感谢您的帮助.

推荐答案

在应该创建向导的tableadapter上调用.fill命令.

Call the .fill command on the tableadapter that the wizard should have created.

默认情况下,代码放置在添加了tableadapter和数据集的表单的load事件中,因此可以复制粘贴或创建一个新子项并调用它.

By default the code is placed in the load event of the form that you added the tableadapter and dataset to, so either copy paste or creat a new sub and call that.

如果是通过设计器添加的,则在窗体设计器中的TableadapterManager下列出的任何tableadapter都有一个clearBeforeFill属性,如果没有通过设计器添加,则必须在后面的代码中进行设置.

There is a clearBeforeFill property of any tableadapter listed under the TableadapterManager in the Form designer if you added it via the designer, if not then you'll have to set it in your code behind.

在后面的代码中,绑定源上可能会发生多个事件,我建议将所需的代码放在currentItemChanged事件上,以便实时提交更改.

in the code behind there are several events that can occur on your binding source, I would suggest putting the needed code on the currentItemChanged event in order to commit changes in real time.

这篇关于如何刷新数据集以反映数据库的外部更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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