public sealed class CsvDataReader : DbDataReader
Namespace
CsvHelper
Assembly
CsvHelper.dll
Inheritance
object MarshalByRefObject DbDataReader CsvDataReader
Builds
net10.0 netstandard2.1 netstandard2.0 net47

Remarks

A field is DBNull (IsDBNull) when it is one of the reader's CsvReaderOptions.NullValues; an empty field is an empty string unless "" is one of them. The columns are those of the header, or, without a header, of the first record.

Constructors

Properties

Depth

Added in v10.0.0
public override int Depth { get; }

Always 0: CSV is not nested.

Property value

int

View source

FieldCount

Added in v10.0.0
public override int FieldCount { get; }

The number of columns: those of the header, or of the first record.

Property value

int

View source

HasRows

Added in v34.0.0
public override bool HasRows { get; }

true while the data reader is open; whether records remain is only known by reading.

Property value

bool

View source

IsClosed

Added in v10.0.0
public override bool IsClosed { get; }

Whether Close has been called.

Property value

bool

View source

RecordsAffected

Added in v10.0.0
public override int RecordsAffected { get; }

Always -1: reading changes no records.

Property value

int

View source

Indexers

this[int]

Added in v10.0.0
public override object this[int ordinal] { get; }

Gets the value of column ordinal. See GetValue.

Parameters

ordinalint
The 0-based index of the column.

Property value

object

View source

this[string]

Added in v10.0.0
public override object this[string name] { get; }

Gets the value of the column called name. See GetValue.

Parameters

namestring
The name of the column.

Property value

object

View source

Methods

Close()

Added in v10.0.0
public override void Close()

Closes the data reader, and disposes the CSV reader unless it was created with leaveOpen.

View source

GetByte(int)

Added in v10.0.0
public override byte GetByte(int ordinal)

Parses the field as a byte, in the reader's format provider.

Parameters

ordinalint
The 0-based index of the column.

Returns

byte
The parsed value.

Exceptions

FormatException
The field is not a number.
OverflowException
The field is outside the range of byte.

View source

public override long GetBytes(int ordinal, long dataOffset, byte[]? buffer, int bufferOffset, int length)

Copies the UTF-8 bytes of the field into buffer.

Parameters

ordinalint
The 0-based index of the column.
dataOffsetlong
The offset in the field to start copying from.
bufferbyte[]?
Receives the bytes, or null to get the length of the field.
bufferOffsetint
The offset in buffer to copy to.
lengthint
The largest number of bytes to copy.

Returns

long
The number of bytes copied, or the length of the field when buffer is null.

View source

GetChar(int)

Added in v10.0.0
public override char GetChar(int ordinal)

Gets the first character of the field.

Parameters

ordinalint
The 0-based index of the column.

Returns

char
The first character.

Exceptions

InvalidCastException
The field is empty.

View source

public override long GetChars(int ordinal, long dataOffset, char[]? buffer, int bufferOffset, int length)

Copies the characters of the field into buffer.

Parameters

ordinalint
The 0-based index of the column.
dataOffsetlong
The offset in the field to start copying from.
bufferchar[]?
Receives the characters, or null to get the length of the field.
bufferOffsetint
The offset in buffer to copy to.
lengthint
The largest number of characters to copy.

Returns

long
The number of characters copied, or the length of the field when buffer is null.

View source

GetDataTypeName(int)

Added in v10.0.0
public override string GetDataTypeName(int ordinal)

Always String.

Parameters

ordinalint
The 0-based index of the column.

Returns

string
String.

View source

GetInt16(int)

Added in v10.0.0
public override short GetInt16(int ordinal)

Parses the field as a short, in the reader's format provider.

Parameters

ordinalint
The 0-based index of the column.

Returns

short
The parsed value.

Exceptions

FormatException
The field is not a number.
OverflowException
The field is outside the range of short.

View source

GetName(int)

Added in v10.0.0
public override string GetName(int ordinal)

Gets the name of column ordinal.

Parameters

ordinalint
The 0-based index of the column.

Returns

string
The header name, or Column and the 1-based number without a header.

Exceptions

IndexOutOfRangeException
ordinal is not a column.

View source

GetSchemaTable()

Added in v10.0.0
public override DataTable GetSchemaTable()

Describes the columns for DataTable.Load and other consumers: their names, ordinals and type (string), all of them nullable.

Returns

DataTable
A table with a row per column.

View source

GetValues(object[])

Added in v10.0.0
public override int GetValues(object[] values)

Copies the values of the current record into values. See GetValue.

Parameters

valuesobject[]
Receives the values, up to its length.

Returns

int
The number of values copied.

Exceptions

ArgumentNullException
values is null.

View source

NextResult()

Added in v10.0.0
public override bool NextResult()

Always false: a CSV file has one result set.

Returns

bool
false.

View source