SqlDataReader.GetBytes(Int32, Int64, Byte[], Int32, Int32) 方法

定義

從指定的資料行位移將字元的資料流讀入做為陣列的緩衝區,開始於指定的緩衝區位移。Reads a stream of bytes from the specified column offset into the buffer an array starting at the given buffer offset.

public:
 virtual long GetBytes(int i, long dataIndex, cli::array <System::Byte> ^ buffer, int bufferIndex, int length);
public long GetBytes (int i, long dataIndex, byte[] buffer, int bufferIndex, int length);
abstract member GetBytes : int * int64 * byte[] * int * int -> int64
override this.GetBytes : int * int64 * byte[] * int * int -> int64
Public Function GetBytes (i As Integer, dataIndex As Long, buffer As Byte(), bufferIndex As Integer, length As Integer) As Long

參數

i
Int32

以零為基底的資料行序數。The zero-based column ordinal.

dataIndex
Int64

要開始讀取作業之資料欄位中的來源索引。The index within the field from which to begin the read operation.

buffer
Byte[]

要將位元組資料流讀取到其中的緩衝區。The buffer into which to read the stream of bytes.

bufferIndex
Int32

buffer 內寫入作業開始之處的索引。The index within the buffer where the write operation is to start.

length
Int32

複製入緩衝區的最大長度。The maximum length to copy into the buffer.

傳回

讀取的實際位元組數目。The actual number of bytes read.

實作

備註

GetBytes 會傳回欄位中可用的位元組數目。GetBytes returns the number of available bytes in the field. 大部分的時間都是欄位的確切長度。Most of the time this is the exact length of the field. 不過,如果 GetBytes 已經用來從欄位取得位元組,傳回的數位可能會小於欄位的真正長度。However, the number returned may be less than the true length of the field if GetBytes has already been used to obtain bytes from the field. 例如,如果 SqlDataReader 將大型資料結構讀入緩衝區中,就會發生這種情況。This may be the case, for example, if the SqlDataReader is reading a large data structure into a buffer. 如需詳細資訊,請參閱 CommandBehaviorSequentialAccess 設定。For more information, see the SequentialAccess setting for CommandBehavior.

如果您傳遞 null的緩衝區,GetBytes 會傳回整個欄位的長度(以位元組為單位),而不是以緩衝區位移參數為基礎的剩餘大小。If you pass a buffer that is null, GetBytes returns the length of the entire field in bytes, not the remaining size based on the buffer offset parameter.

不會執行任何轉換;因此,抓取的資料必須已經是位元組陣列。No conversions are performed; therefore, the data retrieved must already be a byte array.

適用於

另請參閱