共用方式為


OdbcDataReader.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.Odbc;

class Class1 {
   public static void Main() {

      using (OdbcConnection connection =
         new OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Northwind.mdb")) {

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

         OdbcCommand command = new OdbcCommand("select * from Shippers", connection);
         connection.Open();
         OdbcDataReader 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.Odbc

Module Module1
   Public Sub Main()
      Using connection As New OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Northwind.mdb")
         Dim command As New OdbcCommand("select * from Shippers", connection)

         connection.Open()
         Dim reader As OdbcDataReader = 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

適用於

另請參閱