DataTableExtensionReadCsv(DataTable, CsvReader, CsvMapping) Method

Adds CSV content as DataRows to the DataTable.

Definition

Namespace: FolkerKinzel.CsvTools.Mappings
Assembly: FolkerKinzel.CsvTools.Mappings (in FolkerKinzel.CsvTools.Mappings.dll) Version: 1.1.0+1263e8243dc2cd78095f678f813d7d9c52ea4315
C#
public static void ReadCsv(
	this DataTable dataTable,
	CsvReader reader,
	CsvMapping mapping
)

Parameters

dataTable  DataTable
The DataTable to which DataRows are added.
reader  CsvReader
The CsvReader to use.
mapping  CsvMapping
The CsvMapping to be used.

Usage Note

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

Remarks

Each PropertyName of mapping MUST have a corresponding DataColumn in dataTable - corresponding in the Caption property (case-insensitive) and the accepted data type.

Effort must be taken that the PropertyNames in mapping are unique, even when treated case-insensitive.

The DynamicProperty instances in mapping don't need to match all columns of the DataTable or all columns of the CSV file (neither in number nor in order).

It's recommended to initialize reader with the DisableCaching flag set.

Exceptions

ArgumentNullExceptiondataTable, or reader, or mapping is null.
ArgumentException There is a DynamicProperty in mapping whose PropertyName finds no corresponding ColumnName in dataTable.
FormatExceptionParsing fails and Throwing is true.
NoNullAllowedExceptionThe mapping doesn't match the schema of the dataTable.
ConstraintExceptionThe parsed CSV data does not match the schema of the dataTable.
IOExceptionI/O error.
ObjectDisposedExceptionThe file was already closed.

See Also