OleDbDataReader.GetValues(Object[]) Metoda
Definicja
Wypełnia tablicę obiektów wartościami kolumn bieżącego wiersza.Populates an array of objects with the column values of the current row.
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, do Object której mają zostać skopiowane kolumny atrybutów.An array of Object into which to copy the attribute columns.
Zwraca
Liczba wystąpień Object w tablicy.The number of instances of Object in the array.
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 efektywny sposób pobierania wszystkich kolumn, a nie pobiera poszczególnych kolumn pojedynczo.For most applications, the GetValues method provides an efficient means for retrieving all columns, instead of retrieving each column individually.
Można przekazać Object tablicę zawierającą mniej niż liczbę kolumn zawartych w wierszu wyników.You can pass an Object array that contains fewer than the number of columns that are contained in the resulting row. Tylko ilość danych, które Object zostały przechowywane przez tablicę, jest kopiowana do tablicy.Only the amount of data the Object array holds is copied to the array. Można również przekazać Object tablicę, której długość jest większa niż liczba kolumn zawartych w wierszu.You can also pass an Object array whose length is more than the number of columns that are contained in the resulting row.
Ta metoda zwraca DBNull dla kolumn bazy danych o wartości null.This method returns DBNull for null database columns.