CsvConverterWrite(DataTable, CsvWriter, CsvMapping) Method

Writes the content of a DataTable as CSV.

Definition

Namespace: FolkerKinzel.CsvTools.Mappings
Assembly: FolkerKinzel.CsvTools.Mappings (in FolkerKinzel.CsvTools.Mappings.dll) Version: 1.1.0+1263e8243dc2cd78095f678f813d7d9c52ea4315
C#
public static void Write(
	DataTable dataTable,
	CsvWriter writer,
	CsvMapping mapping
)

Parameters

dataTable  DataTable
The DataTable whose content is written.
writer  CsvWriter
The CsvWriter to be used.
mapping  CsvMapping
The CsvMapping to be used.

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).

Exceptions

ArgumentNullExceptiondataTable, or writer, or mapping is null.
ArgumentException There is a DynamicProperty in mapping whose PropertyName finds no corresponding ColumnName in dataTable.
InvalidCastException A value in dataTable does not match the expected data type in mapping.
FormatException One of the TypeConverterT instances uses an invalid format string.
IOExceptionI/O error.
ObjectDisposedExceptionThe file was already closed.

See Also