OleDbDataReader.GetValues(Object[]) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
Parameters
Returns
The number of instances of Object in the array.
Implements
Examples
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
Remarks
For most applications, the GetValues method provides an efficient means for retrieving all columns, instead of retrieving each column individually.
You can pass an Object array that contains fewer than the number of columns that are contained in the resulting row. Only the amount of data the Object array holds is copied to the array. You can also pass an Object array whose length is more than the number of columns that are contained in the resulting row.
This method returns DBNull for null database columns.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기