DataTableReader.GetValues(Object[]) DataTableReader.GetValues(Object[]) DataTableReader.GetValues(Object[]) DataTableReader.GetValues(Object[]) Method

定義

オブジェクトの配列に現在行の列値を設定します。Populates an array of objects with the column values of the current row.

public:
 override int GetValues(cli::array <System::Object ^> ^ values);
public override int GetValues (object[] values);
override this.GetValues : obj[] -> int
Public Overrides Function GetValues (values As Object()) As Integer

パラメーター

values
Object[]

Object の列の値のコピー先である DataTableReader の配列。An array of Object into which to copy the column values from the DataTableReader.

戻り値

配列にコピーされる列の値の数。The number of column values copied into the array.

例外

渡されたインデックスが 0 から FieldCount - 1 の範囲にありません。The index passed was outside the range of 0 to FieldCount - 1.

削除した行からデータを取得しようとしました。An attempt was made to retrieve data from a deleted row.

閉じている DataTableReader の列を読み取るかアクセスしようとしました。An attempt was made to read or access a column in a closed DataTableReader .

次の例は、正しいサイズの配列を使用して、指定DataTableReaderされたの現在の行からすべての値を読み取る方法を示しています。The following example demonstrates using an array that is the correct size, to read all values from the current row in the supplied DataTableReader. また、このサンプルでは、サイズの小さい、または使用可能な列数よりも大きいサイズの固定配列を使用する方法を示します。In addition, the sample demonstrates using a fixed-sized array that could be either smaller or larger than the number of available columns.

private static void TestGetValues(DataTableReader reader)
{
    // Given a DataTableReader, use the GetValues
    // method to retrieve a full row of data.
    // Test the GetValues method, passing in an array large
    // enough for all the columns.
    Object[] values = new Object[reader.FieldCount];
    int fieldCount = reader.GetValues(values);

    Console.WriteLine("reader.GetValues retrieved {0} columns.",
        fieldCount);
    for (int i = 0; i < fieldCount; i++)
        Console.WriteLine(values[i]);

    Console.WriteLine();

    // Now repeat, using an array that may contain a different 
    // number of columns than the original data. This should work correctly,
    // whether the size of the array is larger or smaller than 
    // the number of columns.

    // Attempt to retrieve three columns of data.
    values = new Object[3];
    fieldCount = reader.GetValues(values);
    Console.WriteLine("reader.GetValues retrieved {0} columns.",
        fieldCount);
    for (int i = 0; i < fieldCount; i++)
        Console.WriteLine(values[i]);
}
Private Sub TestGetValues(ByVal reader As DataTableReader)

    ' Given a DataTableReader, use the GetValues
    ' method to retrieve a full row of data.

    ' Test the GetValues method, passing in an array large
    ' enough for all the columns.
    Dim values(reader.FieldCount - 1) As Object
    Dim fieldCount As Integer = reader.GetValues(values)
    Console.WriteLine("reader.GetValues retrieved {0} columns.", _
         fieldCount)
    For i As Integer = 0 To fieldCount - 1
        Console.WriteLine(values(i))
    Next

    Console.WriteLine()

    ' Now repeat, using an array that may contain a different 
    ' number of columns than the original data. This should work correctly,
    ' whether the size of the array is larger or smaller than 
    ' the number of columns.

    ' Attempt to retrieve three columns of data.
    ReDim values(2)
    fieldCount = reader.GetValues(values)
    Console.WriteLine("reader.GetValues retrieved {0} columns.", _
         fieldCount)
    For i As Integer = 0 To fieldCount - 1
        Console.WriteLine(values(i))
    Next
End Sub

注釈

ほとんどのアプリケーションでは、この方法により、各列を個別に取得するのではなく、すべての列を取得するための効率的な手段が提供されます。For most applications, this method provides an efficient means for retrieving all columns, instead of retrieving each column individually. 内のDataTableReader行からすべての列の値を取得することが目的であるGetValues場合、メソッドは最も効率的なソリューションを提供します。If your intent is to retrieve all the column values from a row within the DataTableReader, the GetValues method provides the most efficient solution.

結果の行にObject含まれる列数よりも小さい配列を渡すことができます。You can pass an Object array that contains fewer than the number of columns that are contained in the resulting row. 配列に格納できるデータObject量だけが配列にコピーされます。Only the amount of data the Object array can hold is copied to the array. また、長さが結果Objectの行に含まれる列数よりも長い配列を渡すこともできます。この場合、追加の配列要素はメソッド呼び出しによって変更されません。You can also pass an Object array whose length is more than the number of columns that are contained in the resulting row, in which case the additional array elements remains unchanged by the method call.

このメソッドはDBNull 、null 列の出力配列にを格納します。This method places DBNull in the output array for null columns.

適用対象