OleDbDataReader.GetValues(Object[]) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
使用目前資料列的資料行值填入物件陣列。
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
參數
傳回
陣列中 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。