DataSet.Load Method (IDataReader, LoadOption, String[])
Assembly: System.Data (in system.data.dll)
public: void Load ( IDataReader^ reader, LoadOption loadOption, ... array<String^>^ tables )
public void Load ( IDataReader reader, LoadOption loadOption, String[] tables )
public function Load ( reader : IDataReader, loadOption : LoadOption, ... tables : String[] )
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.
- tables
An array of strings, from which the Load method retrieves table name 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 Load method for more information on using this parameter.
The tables parameter allows you to specify an array of table names, indicating the order of the tables corresponding to each result set loaded from the reader. The Load method attempts to find a table within the DataSet matching the name found in the array of table names, in order. If a matching table is found, that table is loaded with the content of the current result set. If no matching table is found, a table is created using the name supplied in the array of table names, and the new table's schema is inferred from the result set. After each result set, the Load method moves on to the next result set within the reader, until there are no more result sets.
The default namespace associated with DataSet, if any, is associated with each newly created DataTable. The name resolution scheme for this method is the same as that followed by the Fill method of the DbDataAdapter class.
The following Console application example first creates tables and loads data from a reader into a DataSet, using the Load method. The example then adds tables to a DataSet and attempts to fill the tables with data from a DataTableReader. In this example, because the parameters passed to the Load method indicate a table name that does not exist, the Load method creates a new table to match the name passed as a parameter. Once the data has been loaded, the example displays the contents of all its tables in the Console window.
The example displays the following text in the Console window:
Customers ========================= 0 Mary 1 Andy 2 Peter Products ========================= 0 Wireless Network Card 1 Hard Drive 2 Monitor 3 CPU Customers ========================= 0 Mary 1 Andy 2 Peter Products ========================= 0 Wireless Network Card 1 Hard Drive 2 Monitor 3 CPU NewCustomers ========================= 0 Mary 1 Andy 2 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.