Click or drag to resize

EnumerableExtensionToDataTableT Method (IEnumerableT, IncompatibleDataColumnTypeHandling, CultureInfo)

Creates a DataTable from an IEnumerable{T}. Each element of the given source results in a row representing the properties of {T} as columns. If conversion is needed, the default converter is used.

Namespace:  TB.ComponentModel
Assembly:  UniversalTypeConverter (in UniversalTypeConverter.dll) Version: 2.0.0
Syntax
C#
public static DataTable ToDataTable<T>(
	this IEnumerable<T> source,
	IncompatibleDataColumnTypeHandling incompatibleDataColumnTypeHandling = IncompatibleDataColumnTypeHandling.ToString,
	CultureInfo culture = null
)

Parameters

source
Type: System.Collections.GenericIEnumerableT
The IEnumerable{T} to create a DataTable from.
incompatibleDataColumnTypeHandling (Optional)
Type: TB.ComponentModelIncompatibleDataColumnTypeHandling
Defines how a type is handled if not valid for a DataColumn of a DataTable. ToString is used by default.
culture (Optional)
Type: System.GlobalizationCultureInfo
The culture to use if conversion is needed. If not given or null, the DefaultCulture is used.

Type Parameters

T
The type of the elements of source.

Return Value

Type: DataTable
A DataTable representing each element of the given source as a row.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableT. 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).
See Also