DataTableCollection.AddRange Method
.NET Framework 4.5
Copies the elements of the specified DataTable array to the end of the collection.
Namespace: System.Data
Assembly: System.Data (in System.Data.dll)
The following example creates two DataTable objects and adds them to the DataTableCollection of a DataSet.
public static void DataTableCollectionAddRange() { // create a DataSet with two tables DataSet dataSet = new DataSet(); // create Customer table DataTable customersTable = new DataTable("Customers"); customersTable.Columns.Add("customerId", typeof(int)).AutoIncrement = true; customersTable.Columns.Add("name", typeof(string)); customersTable.PrimaryKey = new DataColumn[] { customersTable.Columns["customerId"] }; // create Orders table DataTable ordersTable = new DataTable("Orders"); ordersTable.Columns.Add("orderId", typeof(int)).AutoIncrement = true; ordersTable.Columns.Add("customerId", typeof(int)); ordersTable.Columns.Add("amount", typeof(double)); ordersTable.PrimaryKey = new DataColumn[] { ordersTable.Columns["orderId"] }; dataSet.Tables.AddRange(new DataTable[] { customersTable, ordersTable }); // print the tables and their columns foreach (DataTable table in dataSet.Tables) { Console.WriteLine(table.TableName); foreach (DataColumn column in table.Columns) { Console.Write("{0}\table", column.ColumnName); } Console.WriteLine(); } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.