DataSet.Load Method (IDataReader, LoadOption, FillErrorEventHandler, DataTable[])
Assembly: System.Data (in system.data.dll)
public: virtual void Load ( IDataReader^ reader, LoadOption loadOption, FillErrorEventHandler^ errorHandler, ... array<DataTable^>^ tables )
public void Load ( IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler, DataTable[] tables )
public function Load ( reader : IDataReader, loadOption : LoadOption, errorHandler : FillErrorEventHandler, ... tables : DataTable[] )
Parameters
- reader
An IDataReader that provides one or more result sets.
- loadOption
A value from the LoadOption enumeration that indicates how rows already in the DataTable instances within the DataSet will be combined with incoming rows that share the same primary key.
- errorHandler
A FillErrorEventHandler delegate to call when an error occurs while loading data.
- tables
An array of DataTable instances, from which the Load method retrieves name and namespace information.
The Load method provides a technique for filling a single DataTable with data, retrieved from an IDataReader instance. This method provides the same functionality, but allows you to load multiple result sets from an IDataReader into multiple tables within a DataSet.
The loadOption parameter allows you to specify how you want the imported data to interact with existing data, and can be any of the values from the LoadOption enumeration. See the documentation for the DataTableLoad method for more information on using this parameter.
The errorHandler parameter is a FillErrorEventHandler delegate that refers to a procedure that is called when an error occurs while loading data. The FillErrorEventArgs parameter passed to the procedure provides properties that allow you to retrieve information about the error that occurred, the current row of data, and the DataTable being filled. Using this delegate mechanism, rather than a simpler try/catch block, allows you to determine the error, handle the situation, and continue processing if you like. The FillErrorEventArgs parameter supplies a Continue property: set this property to true to indicate that you have handled the error and wish to continue processing; set the property to false to indicate that you wish to halt processing. Be aware that setting the property to false causes the code that triggered the problem to throw an exception.
The tables parameter allows you to specify an array of DataTable instances, indicating the order of the tables corresponding to each result set loaded from the reader. The Loadmethod fills each supplied DataTable instance with data from a single result set from the source data reader. After each result set, the Loadmethod moves on to the next result set within the reader, until there are no more result sets.
The name resolution scheme for this method is the same as that followed by the Fill method of the DbDataAdapter class.
The following example adds a table to a DataSet, and then attempts to use the Load method to load data from a DataTableReader that contains an incompatible schema. Rather than trapping the error, this example uses a FillErrorEventHandler delegate to investigate and handle the error.
The example displays the following output in the console window:
Error when attempting to update the value: Mary Error when attempting to update the value: Andy Error when attempting to update the value: Peter
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.