同步数据集 [英] Synchronize DataSet

查看:125
本文介绍了同步数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是数据库中的同步数据一个数据集的最佳方法?下面是参数:

What is the best approach to synchronizing a DataSet with data in a database? Here are the parameters:

  • 我们不能简单地重新加载,因为它绑定到用户可能配置有哪些UI控件的数据(这是一个树网格,他们可能展开/折叠)
  • 我们不能使用changeflag(如UpdatedTimeStamp)的数据库中,因为变化并不总是流过的应用程序(如数据库管理员可以使用SQL语句更新域)
  • 我们不能使用UPDATE触发器在数据库中,因为它是一个多用户系统
  • 我们正在使用ADO.NET数据集
  • 在一个给定行的多个字段可修改

我看数据集的合并功能,但是这似乎并没有保持一个ID列的概念。我看着的DiffGram能力,但这里的问题是那些似乎是从同一个DataSet中的变化,而不是发生一些外部数据源的变化产生的。

I've looked at the DataSet's Merge capability, but this doesn't seem to keep the notion of an "ID" column. I've looked at DiffGram capability but the issue here is those seem to be generated from changes within the same DataSet rather than changes that occured on some external data source.

我一直在运行,从这个解决方案一段时间,但我知道这个方法是有效的(有很多的低效追)是构建一个独立的数据集,然后遍历应用更改,逐个字段的所有行,该数据集对其加以约束。

I've been running from this solution for a while but the approach I know would work (with a lot of ineffeciency) is to build a separate DataSet and then iterate all rows applying changes, field by field, to the DataSet on which it is bound.

有没有人有类似的情况?你是如何解决这个问题呢?即使你没有碰到类似的问题,一个解决方案的任何建议是AP preciated。

Has anyone had a similar scenario? What did you do to solve the problem? Even if you haven't run into a similar problem, any recommendation for a solution is appreciated.

感谢

推荐答案

DataSet.Merge很适合这个的如果的你必须为每个数据表定义主键;该数据集将提高改变事件的任何数据绑定GUI控件

DataSet.Merge works well for this if you have a primary key defined for each DataTable; the DataSet will raise changed events to any databound GUI controls

如果你的表是小,你可以只是重新读取所有的行,并定期合并,否则限制设定要读取一个时间戳是一个好主意 -​​ 只是告诉数据库管理员要遵循的规则和更新时间戳; - )

if your table is small you can just re-read all of the rows and merge periodically, otherwise limiting the set to be read with a timestamp is a good idea - just tell the DBAs to follow the rules and update the timestamp ;-)

另一种选择 - 这是一些工作 - 是使用触发器或存储过程和基本刷新查询掉在队列中的时间标记,以保持一个改变行队列(时间戳,行ID);如果基础表中有很多在这行,让你(通过内部连接队列记录)拉仅将更改的行自上次调查时这将是更有效的。

another option - which is a bit of work - is to keep a changed-row queue (timestamp, row ID) using a trigger or stored procedure, and base the refresh queries off of the timestamp in the queue; this will be more efficient if the base table has a lot of rows in it, allowing you (via an inner join on the queue record) to pull only the changed rows since the last poll time.

这篇关于同步数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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