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。
适用于
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈