Skip to main content

Class CsvDataReader

The CsvDataReader class enables forward-only reading of data from a CSV file, implementing the System.Data.IDataReader interface. If you need to interact with a CsvDataReader directly, you can process all the data from a Csv File using a while loop like this:

` var reader = new CsvDataReader(stream); while (reader.Read())

`

Namespace: Workspace.XBR.Xperiflow.Etl.Tabular

Assembly: Xperiflow.dll

Declaration
public class CsvDataReader : IDataReader, IDataRecord, IDisposable

Implements: System.Data.IDataReader, System.Data.IDataRecord, System.IDisposable

Properties

Depth

Returns 0 for a CsvDataReader

Declaration
public int Depth { get; }

IsClosed

Gets a value indicating whether the data reader is closed.

Declaration
public bool IsClosed { get; }

RecordsAffected

Returns 0 for a CsvDataReader

Declaration
public int RecordsAffected { get; }

FieldCount

returns the number of columns in the Csv data, or 0 if no data is available

Declaration
public int FieldCount { get; }

this[int]

Gets the column located at the specified index.

Declaration
public object this[int i] { get; }

this[string]

Gets the column with the specified name.

Declaration
public object this[string name] { get; }

Methods

GetSchemaTable()

Returns a System.Data.DataTable that describes the column metadata of the System.Data.IDataReader.

Returns null if the executed command returned no resultset, or after System.Data.IDataReader.NextResult returns false.

Declaration
public DataTable? GetSchemaTable()
Returns

System.Data.DataTable

A System.Data.DataTable that describes the column metadata.

Exceptions

System.InvalidOperationException The System.Data.IDataReader is closed.

NextResult()

Advances the reader to the next result

Declaration
public bool NextResult()
Returns

System.Boolean

true if there are more result sets; otherwise, false

Read()

Advances the System.Data.IDataReader to the next record.

Declaration
public bool Read()
Returns

System.Boolean

true if there are more rows; otherwise, false.

Close()

Closes the System.Data.IDataReader Object.

Declaration
public void Close()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public void Dispose()

GetName(int)

Gets the Column Name at the specified index

Declaration
public string GetName(int i)
Returns

System.String

The Column Name

Parameters
TypeNameDescription
System.Int32iThe column index
Exceptions

System.IndexOutOfRangeException

GetOrdinal(string)

Returns the column index of the specified column name

Declaration
public int GetOrdinal(string name)
Returns

System.Int32

The column index

Parameters
TypeNameDescription
System.StringnameThe name of the column
Exceptions

System.ArgumentException If the provided column name does not exist

GetValue(int)

Returns the value of the specified column at the current row

Declaration
public object GetValue(int i)
Returns

System.Object

The string value of the column

Parameters
TypeNameDescription
System.Int32iThe column index

GetString(int)

Gets the string value of the specified field.

Declaration
public string GetString(int i)
Returns

System.String

The string value of the specified field.

Parameters
TypeNameDescription
System.Int32iThe index of the field to find.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetBoolean(int)

Gets the value of the specified column as a Boolean.

Declaration
public bool GetBoolean(int i)
Returns

System.Boolean

The value of the column.

Parameters
TypeNameDescription
System.Int32iThe zero-based column ordinal.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetByte(int)

Gets the 8-bit unsigned integer value of the specified column.

Declaration
public byte GetByte(int i)
Returns

System.Byte

The 8-bit unsigned integer value of the specified column.

Parameters
TypeNameDescription
System.Int32iThe zero-based column ordinal.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetChar(int)

Gets the character value of the specified column.

Declaration
public char GetChar(int i)
Returns

System.Char

The character value of the specified column.

Parameters
TypeNameDescription
System.Int32iThe zero-based column ordinal.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetDataTypeName(int)

Gets the data type information for the specified field.

Declaration
public string GetDataTypeName(int i)
Returns

System.String

The data type information for the specified field.

Parameters
TypeNameDescription
System.Int32iThe index of the field to find.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetDateTime(int)

Gets the date and time data value of the specified field.

Declaration
public DateTime GetDateTime(int i)
Returns

System.DateTime

The date and time data value of the specified field.

Parameters
TypeNameDescription
System.Int32iThe index of the field to find.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetGuid(int)

Returns the GUID value of the specified field.

Declaration
public Guid GetGuid(int i)
Returns

System.Guid

The GUID value of the specified field.

Parameters
TypeNameDescription
System.Int32iThe index of the field to find.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetFieldType(int)

Gets the System.Type information corresponding to the type of System.Object that would be returned from System.Data.IDataRecord.GetValue(System.Int32).

Declaration
public Type GetFieldType(int i)
Returns

System.Type

The System.Type information corresponding to the type of System.Object that would be returned from System.Data.IDataRecord.GetValue(System.Int32).

Parameters
TypeNameDescription
System.Int32iThe index of the field to find.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

IsDBNull(int)

Returns true if the value of the specified column is an empty string or null

Declaration
public bool IsDBNull(int i)
Returns

System.Boolean

True if the value is an empty string or null, otherwise false

Parameters
TypeNameDescription
System.Int32iThe column index

GetDecimal(int)

Gets the fixed-position numeric value of the specified field.

Declaration
public decimal GetDecimal(int i)
Returns

System.Decimal

The fixed-position numeric value of the specified field.

Parameters
TypeNameDescription
System.Int32iThe index of the field to find.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetDouble(int)

Gets the double-precision floating point number of the specified field.

Declaration
public double GetDouble(int i)
Returns

System.Double

The double-precision floating point number of the specified field.

Parameters
TypeNameDescription
System.Int32iThe index of the field to find.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetFloat(int)

Gets the single-precision floating point number of the specified field.

Declaration
public float GetFloat(int i)
Returns

System.Single

The single-precision floating point number of the specified field.

Parameters
TypeNameDescription
System.Int32iThe index of the field to find.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetInt16(int)

Gets the 16-bit signed integer value of the specified field.

Declaration
public short GetInt16(int i)
Returns

System.Int16

The 16-bit signed integer value of the specified field.

Parameters
TypeNameDescription
System.Int32iThe index of the field to find.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetInt32(int)

Gets the 32-bit signed integer value of the specified field.

Declaration
public int GetInt32(int i)
Returns

System.Int32

The 32-bit signed integer value of the specified field.

Parameters
TypeNameDescription
System.Int32iThe index of the field to find.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetInt64(int)

Gets the 64-bit signed integer value of the specified field.

Declaration
public long GetInt64(int i)
Returns

System.Int64

The 64-bit signed integer value of the specified field.

Parameters
TypeNameDescription
System.Int32iThe index of the field to find.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetBytes(int, long, byte[]?, int, int)

Reads a stream of bytes from the specified column offset into the buffer as an array, starting at the given buffer offset.

Declaration
public long GetBytes(int i, long fieldOffset, byte[]? buffer, int bufferoffset, int length)
Returns

System.Int64

The actual number of bytes read.

Parameters
TypeNameDescription
System.Int32iThe zero-based column ordinal.
System.Int64fieldOffsetThe index within the field from which to start the read operation.
System.Byte[]bufferThe buffer into which to read the stream of bytes.
System.Int32bufferoffsetThe index for buffer to start the read operation.
System.Int32lengthThe number of bytes to read.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetChars(int, long, char[]?, int, int)

Reads a stream of characters from the specified column offset into the buffer as an array, starting at the given buffer offset.

Declaration
public long GetChars(int i, long fieldoffset, char[]? buffer, int bufferoffset, int length)
Returns

System.Int64

The actual number of characters read.

Parameters
TypeNameDescription
System.Int32iThe zero-based column ordinal.
System.Int64fieldoffsetThe index within the row from which to start the read operation.
System.Char[]bufferThe buffer into which to read the stream of bytes.
System.Int32bufferoffsetThe index for buffer to start the read operation.
System.Int32lengthThe number of bytes to read.
Exceptions

System.IndexOutOfRangeException The index passed was outside the range of 0 through System.Data.IDataRecord.FieldCount.

GetValues(object[])

Populates an array of objects with the column values of the current record.

Declaration
public int GetValues(object[] values)
Returns

System.Int32

The number of instances of System.Object in the array.

Parameters
TypeNameDescription
System.Object[]valuesAn array of System.Object to copy the attribute fields into.

GetData(int)

Not implemented for CSV

Declaration
public IDataReader GetData(int i)
Returns

System.Data.IDataReader

Not Supported Exception

Parameters
TypeName
System.Int32i
Exceptions

System.NotSupportedException

Implements

  • System.Data.IDataReader
  • System.Data.IDataRecord
  • System.IDisposable

Inherited Members

  • System.Object.Equals(System.Object)
  • System.Object.Equals(System.Object,System.Object)
  • System.Object.GetHashCode
  • System.Object.GetType
  • System.Object.MemberwiseClone
  • System.Object.ReferenceEquals(System.Object,System.Object)
  • System.Object.ToString

Was this page helpful?