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
public class CsvDataReader : IDataReader, IDataRecord, IDisposable
Implements:
System.Data.IDataReader
, System.Data.IDataRecord
, System.IDisposable
Properties
Depth
Returns 0 for a CsvDataReader
public int Depth { get; }
IsClosed
Gets a value indicating whether the data reader is closed.
public bool IsClosed { get; }
RecordsAffected
Returns 0 for a CsvDataReader
public int RecordsAffected { get; }
FieldCount
returns the number of columns in the Csv data, or 0 if no data is available
public int FieldCount { get; }
this[int]
Gets the column located at the specified index.
public object this[int i] { get; }
this[string]
Gets the column with the specified name.
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.
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
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.
public bool Read()
Returns
System.Boolean
true if there are more rows; otherwise, false.
Close()
Closes the System.Data.IDataReader
Object.
public void Close()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetName(int)
Gets the Column Name at the specified index
public string GetName(int i)
Returns
System.String
The Column Name
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The column index |
Exceptions
System.IndexOutOfRangeException
GetOrdinal(string)
Returns the column index of the specified column name
public int GetOrdinal(string name)
Returns
System.Int32
The column index
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The 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
public object GetValue(int i)
Returns
System.Object
The string value of the column
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The column index |
GetString(int)
Gets the string value of the specified field.
public string GetString(int i)
Returns
System.String
The string value of the specified field.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The 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.
public bool GetBoolean(int i)
Returns
System.Boolean
The value of the column.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The 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.
public byte GetByte(int i)
Returns
System.Byte
The 8-bit unsigned integer value of the specified column.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The 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.
public char GetChar(int i)
Returns
System.Char
The character value of the specified column.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The 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.
public string GetDataTypeName(int i)
Returns
System.String
The data type information for the specified field.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The 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.
public DateTime GetDateTime(int i)
Returns
System.DateTime
The date and time data value of the specified field.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The 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.
public Guid GetGuid(int i)
Returns
System.Guid
The GUID value of the specified field.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The 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)
.
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
Type | Name | Description |
---|---|---|
System.Int32 | i | The 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
public bool IsDBNull(int i)
Returns
System.Boolean
True if the value is an empty string or null, otherwise false
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The column index |
GetDecimal(int)
Gets the fixed-position numeric value of the specified field.
public decimal GetDecimal(int i)
Returns
System.Decimal
The fixed-position numeric value of the specified field.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The 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.
public double GetDouble(int i)
Returns
System.Double
The double-precision floating point number of the specified field.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The 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.
public float GetFloat(int i)
Returns
System.Single
The single-precision floating point number of the specified field.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The 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.
public short GetInt16(int i)
Returns
System.Int16
The 16-bit signed integer value of the specified field.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The 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.
public int GetInt32(int i)
Returns
System.Int32
The 32-bit signed integer value of the specified field.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The 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.
public long GetInt64(int i)
Returns
System.Int64
The 64-bit signed integer value of the specified field.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The 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.
public long GetBytes(int i, long fieldOffset, byte[]? buffer, int bufferoffset, int length)
Returns
System.Int64
The actual number of bytes read.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The zero-based column ordinal. |
System.Int64 | fieldOffset | The index within the field from which to start the read operation. |
System.Byte[] | buffer | The buffer into which to read the stream of bytes. |
System.Int32 | bufferoffset | The index for buffer to start the read operation. |
System.Int32 | length | The 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.
public long GetChars(int i, long fieldoffset, char[]? buffer, int bufferoffset, int length)
Returns
System.Int64
The actual number of characters read.
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | The zero-based column ordinal. |
System.Int64 | fieldoffset | The index within the row from which to start the read operation. |
System.Char[] | buffer | The buffer into which to read the stream of bytes. |
System.Int32 | bufferoffset | The index for buffer to start the read operation. |
System.Int32 | length | The 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.
public int GetValues(object[] values)
Returns
System.Int32
The number of instances of System.Object
in the array.
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | values | An array of System.Object to copy the attribute fields into. |
GetData(int)
Not implemented for CSV
public IDataReader GetData(int i)
Returns
System.Data.IDataReader
Not Supported Exception
Parameters
Type | Name |
---|---|
System.Int32 | i |
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