Export (0) Print
Expand All

DataTable.Load Method

Fills a DataTable with values from a data source using the supplied IDataReader. If the DataTable already contains rows, the incoming data from the data source is merged with the existing rows.

Name Description
DataTable.Load (IDataReader) Fills a DataTable with values from a data source using the supplied IDataReader. If the DataTable already contains rows, the incoming data from the data source is merged with the existing rows.

Supported by the .NET Compact Framework.

DataTable.Load (IDataReader, LoadOption) Fills a DataTable with values from a data source using the supplied IDataReader. If the DataTable already contains rows, the incoming data from the data source is merged with the existing rows according to the value of the loadOption parameter.

Supported by the .NET Compact Framework.

DataTable.Load (IDataReader, LoadOption, FillErrorEventHandler) Fills a DataTable with values from a data source using the supplied IDataReader using an error-handling delegate.

Supported by the .NET Compact Framework.

The Load method can be used in several common scenarios, all centered around getting data from a specified data source and adding it to the current data container (in this case, a DataTable). These scenarios describe standard usage for a DataTable, describing its update and merge behavior.

A DataTable synchronizes or updates with a single primary data source. The DataTable tracks changes, allowing synchronization with the primary data source. In addition, a DataTable can accept incremental data from one or more secondary data sources. The DataTable isn't responsible for tracking changes in order to allow synchronization with the secondary data source.

Given these two hypothetical data sources, a user is likely to require one of the following behaviors:

  • Initialize DataTable from a primary data source. In this scenario, the user wants to initialize an empty DataTable with values from the primary data source. Later the user intends to propagate changes back to the primary data source.

  • Preserve changes and re-synchronize from the primary data source. In this scenario, the user wants to take the DataTable filled in the previous scenario and perform an incremental synchronization with the primary data source, preserving modifications made in the DataTable.

  • Incremental data feed from secondary data sources. In this scenario, the user wants to merge changes from one or more secondary data sources, and propagate those changes back to the primary data source.

The Load method makes all these scenarios possible. All but one of the overloads for this method allows you to specify a load option parameter, indicating how rows already in a DataTable combine with rows being loaded. (The overload that doesn't allow you to specify the behavior uses the default load option.) The following table describes the three load options provided by the LoadOption enumeration. In each case, the description indicates the behavior when the primary key of a row in the incoming data matches the primary key of an existing row.

Load Option

Description

PreserveChanges (default)

Updates the original version of the row with the value of the incoming row.

OverwriteChanges

Updates the current and original versions of the row with the value of the incoming row.

Upsert

Updates the current version of the row with the value of the incoming row.

In general, the PreserveChanges and OverwriteChanges options are intended for scenarios in which the user needs to synchronize the DataSet and its changes with the primary data source. The Upsert option facilitates aggregating changes from one or more secondary data sources.

Community Additions

ADD
Show:
© 2014 Microsoft