DataTableReader.GetValues(Object[]) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
オブジェクトの配列に現在の行の列値を設定します。
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[]
DataTableReaderから列の値をコピーするObjectの配列。
返品
配列にコピーされた列値の数。
例外
渡されたインデックスが 0 から FieldCount - 1 の範囲外でした。
削除された行からデータを取得しようとしました。
閉じた DataTableReader 内の列の読み取りまたはアクセスが試行されました。
例
次の例では、適切なサイズの配列を使用して、指定された DataTableReaderの現在の行からすべての値を読み取る方法を示します。 さらに、このサンプルでは、使用可能な列の数よりも小さいか大きくなる可能性がある固定サイズの配列の使用を示します。
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
注釈
ほとんどのアプリケーションでは、このメソッドは、各列を個別に取得するのではなく、すべての列を取得するための効率的な手段を提供します。
DataTableReader内の行からすべての列値を取得することを目的とする場合は、GetValuesメソッドが最も効率的なソリューションを提供します。
結果の行に含まれる列の数より少ない列を含む Object 配列を渡すことができます。
Object配列が保持できるデータの量のみが配列にコピーされます。 また、結果の行に含まれる列の数を超える長さの Object 配列を渡すこともできます。その場合、追加の配列要素はメソッド呼び出しによって変更されません。
このメソッドは、null 列の出力配列に DBNull を配置します。