OleDbDataReader.GetValues(Object[]) Metoda

Definicja

Wypełnia tablicę obiektów wartościami kolumn bieżącego wiersza.

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

Parametry

values
Object[]

Tablica, Object do której mają być skopiowane kolumny atrybutów.

Zwraca

Liczba wystąpień Object w tablicy.

Implementuje

Przykłady

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

Uwagi

W przypadku większości aplikacji GetValues metoda zapewnia wydajny sposób pobierania wszystkich kolumn zamiast pobierania poszczególnych kolumn osobno.

Można przekazać tablicę Object zawierającą mniej niż liczbę kolumn zawartych w wierszu wynikowym. Tylko ilość danych Object przechowywanych w tablicy jest kopiowana do tablicy. Można również przekazać tablicę Object , której długość jest większa niż liczba kolumn zawartych w wierszu wynikowym.

Ta metoda zwraca wartość DBNull dla kolumn bazy danych o wartości null.

Dotyczy

Zobacz też