OdbcDataReader.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.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。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應