DataTableExtensions.CopyToDataTable(T) Method (IEnumerable(T), DataTable, LoadOption)
Assembly: System.Data.DataSetExtensions (in System.Data.DataSetExtensions.dll)
static member CopyToDataTable : source:IEnumerable<'T> * table:DataTable * options:LoadOption -> unit when 'T : DataRow
The type of objects in the source sequence, typically DataRow.
Usage NoteIn Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable(). When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
The source sequence does not contain any DataRow objects.
A DataRow in the source sequence is a null reference (Nothing in Visual Basic).
The input sequence can be any IEnumerable(T) source, not only a query over a DataTable. Note that if the source sequence is a query, calling this operator will force immediate execution. Enumerating the source sequence can also cause exceptions to be thrown.
The schema of the destination table is based on the schema of the first DataRow row in the source sequence. The table metadata is extracted from the DataRow metadata and the table values from the column values of the DataRow. For a typed DataTable, types are not preserved. The data and schema are transferred, but the resulting rows of the output table will not be of the typed DataRow type. The RowState and RowError properties are not preserved during the copy from the source DataRow to the returned DataTable.
The generated table returned by the method has the default table name. If you want to name the DataTable, attach it to a DataSet, or perform any other DataTable specific operation, you must do so after the table is created and returned.
For more information, see Creating a DataTable From a Query (LINQ to DataSet).
Windows 8.1, Windows Server 2012 R2, 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.