.NET 表适配器:获取与填充?

.NET Table Adapters: Get vs. Fill?(.NET 表适配器:获取与填充?)

本文介绍了.NET 表适配器:获取与填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理数据库中的数据(强类型或其他类型)时,我似乎总是使用 Get,我从来没有真正需要使用 Fill,尽管在提取和更新数据时我可以很容易地使用 Fill 而不是 get.

I always seem to use Get when working with data (strongly typed or otherwise) from the database and I have never really needed to use Fill although I just as easily could use Fill instead of get when pulling out and updating data.

任何人都可以就每种方法的含义和问题提供指导吗?

Can anyone provide guidance as to the implications and gotchas of each method?

在什么情况下最好使用其中一种?

In what situations is it preferable to use one or the other?

任何性能影响?

提前感谢您的回答!我爱这个社区!

Thanks in advance for the answers! I love this community!

推荐答案

Fill 的一个特殊问题是,如果表已经包含数据,则可能会出现唯一索引异常,例如,查询返回其主键的行已经在表格中了.

A particular gotcha of Fill, if the table already contains data is that you could get unique index exceptions when, for example, the query returns a row whose primary key is already in the table.

我使用过很多数据绑定的 Windows 窗体代码,其中编辑控件或窗体上的网格绑定到表,然后使用填充将更多行从数据库加载到表中.这可能会导致一些有趣的事件触发序列和经验中的间歇性错误.

I've worked with a lot of data-bound Windows Forms code where edit controls or a grid on the form is bound to a table and then Fill is used to load more rows from the database to the table. This can cause some interesting event firing sequences and intermittent errors from experience.

使用 Get 检索具有新结果的新表,然后将表单重新绑定到新表可以避免这种情况.

Using Get to retrieve a new table with the new results then rebinding the form to the new table can avoid situations like this.

我怀疑两者之间的性能差异很大,除非在具有现有行的表上使用 Fill.在这种情况下,表的 BeginLoadData 方法将被忽略,这通常会延迟事件触发和索引重建直到结束.

I doubt there is much performance difference between the two unless using Fill on a table with existing rows. In this case the table's BeginLoadData method is ignored which would normally have delayed event firing and index rebuilding until the end.

这篇关于.NET 表适配器:获取与填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:.NET 表适配器:获取与填充?