DataTableReader::GetChars Method (Int32, Int64, array<Char>^, Int32, Int32)
Returns the value of the specified column as a character array.
Assembly: System.Data (in System.Data.dll)
public: virtual long long GetChars( int ordinal, long long dataIndex, array<wchar_t>^ buffer, int bufferIndex, int length ) override
The zero-based column ordinal.
The index within the field from which to start the read operation.
The buffer into which to read the stream of chars.
The index within the buffer at which to start placing the data.
The maximum length to copy into the buffer.
Return ValueType: System::Int64
The actual number of characters read.
The index passed was outside the range of 0 to FieldCount - 1.
An attempt was made to retrieve data from a deleted row.
An attempt was made to read or access a column in a closed DataTableReader.
The specified column does not contain a character array.
GetChars returns the number of available characters in the field. Most of the time this is the exact length of the field. However, the number returned may be less than the true length of the field if GetChars has already been used to obtain characters from the field.
The actual number of characters read can be less than the requested length, if the end of the field is reached. If you pass a buffer that is null (Nothing in Visual Basic), GetChars returns the length of the entire field in characters, not the remaining size based on the buffer offset parameter.
No conversions are performed; therefore the data to be retrieved must already be a character array or coercible to a character array.
The following example demonstrates the GetChars method. The TestGetChars method expects to be passed a DataTableReader filled with two columns of data: a file name in the first column, and an array of characters in the second. In addition, TestGetChars lets you specify the buffer size to be used as it reads the data from the character array in the DataTableReader. TestGetChars creates a file corresponding to each row of data in the DataTableReader, using the supplied data in the first column of the DataTableReader as the file name.
This procedure demonstrates the use of the GetChars method reading data that was stored in the DataTable as a character array. Any other type of data causes the GetChars method to throw an InvalidCastException.
Available since 2.0