OleDbDataReader.GetValues(Object[]) メソッド

定義

オブジェクトの配列に現在行の列値を設定します。

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

パラメーター

values
Object[]

属性列のコピー先の Object の配列。

戻り値

配列に含まれる Object のインスタンスの数。

実装

using System;
using System.Data;
using System.Data.OleDb;

class Class1 {
   public static void Main() {
      using (OleDbConnection connection =
         new OleDbConnection("Provider=SQLOLEDB;Data Source=(local);Integrated Security=SSPI;Initial Catalog=Northwind")) {

         object[] meta = new object[10];
         bool read;

         OleDbCommand command = new OleDbCommand("select * from Region", connection);

         connection.Open();
         OleDbDataReader reader = command.ExecuteReader();

         if (reader.Read() == true) {
            do {
               int NumberOfColums = reader.GetValues(meta);

               for (int i = 0; i < NumberOfColums; i++)
                  Console.Write("{0} ", meta[i].ToString());

               Console.WriteLine();
               read = reader.Read();
            } while (read == true);
         }
         reader.Close();
      }
   }
}
Imports System.Data
Imports System.Data.OleDb

Module Module1
   Public Sub Main()
      Using connection As New OleDbConnection("Provider=SQLOLEDB;Data Source=(local);Integrated Security=SSPI;Initial Catalog=Northwind")
         Dim command As New OleDbCommand("select * from Region", connection)

         connection.Open()
         Dim reader As OleDbDataReader = command.ExecuteReader()

         Dim NumberOfColums As Integer
         Dim meta As Object() = New Object(10) {}
         Dim read As Boolean

         If reader.Read() = True Then
            Do
               NumberOfColums = reader.GetValues(meta)

               For i As Integer = 0 To NumberOfColums - 1
                  Console.Write("{0} ", meta(i).ToString())
               Next

               Console.WriteLine()
               read = reader.Read()
            Loop While read = True
         End If

         reader.Close()
      End Using
   End Sub
End Module

注釈

ほとんどのアプリケーションでは、 メソッドは GetValues 、各列を個別に取得するのではなく、すべての列を取得するための効率的な手段を提供します。

結果の行に Object 含まれる列の数より少ない数の配列を渡すことができます。 配列が保持する Object データの量のみが配列にコピーされます。 また、結果の行に Object 含まれる列の数を超える長さの配列を渡すこともできます。

null データベース列の場合は、DBNull が返されます。

適用対象

こちらもご覧ください