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

2023-09-04 23:45:03 作者:烂命一条√

我似乎总是使用与数据库中的数据(强类型或其他方式)工作时获取和我从来没有真正需要使用填充,虽然我很容易可以在退出和更新数据使用补充,而不是得到。

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?

在什么情况下是preferable使用一个或其他?

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

任何性能影响?

在此先感谢您的答案!我爱这个社会!

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

推荐答案

填充的特殊疑难杂症,如果表中已包含的数据是,你可以得到唯一索引例外的时候,比如,该查询返回的行的主键是已经在表

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窗体工作code其中编辑控件或窗体上的网格绑定到一个表,然后填充用于从数据库表中加载更多的行。这可能会导致一些有趣的事件触发序列和间歇性错误的经验。

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.

我怀疑有除非使用与现有行的表填写这两个之间没有太大的性能差异。在这种情况下,该表的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.