OleDbEnumerator.GetEnumerator(Type) 方法

定义

使用特定的 OLE DB 枚举数,无需 OleDbDataReader 类的实例即可返回 OleDbEnumerator,该读取器包含有关当前安装的 OLE DB 提供程序的信息。Uses a specific OLE DB enumerator to return an OleDbDataReader that contains information about the currently installed OLE DB providers, without requiring an instance of the OleDbEnumerator class.

public:
 static System::Data::OleDb::OleDbDataReader ^ GetEnumerator(Type ^ type);
public static System.Data.OleDb.OleDbDataReader GetEnumerator (Type type);
static member GetEnumerator : Type -> System.Data.OleDb.OleDbDataReader
Public Shared Function GetEnumerator (type As Type) As OleDbDataReader

参数

type
Type

TypeA Type.

返回

OleDbDataReader

一个 OleDbDataReader,该数据表使用指定的 OLE DB 枚举器包含有关请求的 OLE DB 提供程序的信息。An OleDbDataReader that contains information about the requested OLE DB providers, using the specified OLE DB enumerator.

例外

提供程序不支持 ISourcesRowset。The provider does not support ISourcesRowset.

基础提供程序中出现了异常。An exception has occurred in the underlying provider.

示例

下面的控制台应用程序使用 MSDAENUM 组件检索有关所有 OLE DB 提供程序的信息,并在控制台窗口中显示信息。The following console application uses the MSDAENUM component to retrieve information about all the OLE DB providers and displays the information in the console window.

Imports System.Data  
Imports System.Data.OleDb  

Module Module1  

  Sub Main()  
    Dim enumerator As New OleDbEnumerator  
    Dim reader As OleDbDataReader = _  
     OleDbEnumerator.GetEnumerator(Type.GetTypeFromProgID("MSDAENUM"))  

    DisplayData(reader)  

    Console.WriteLine("Press any key to continue.")  
    Console.ReadKey()  
  End Sub  

  Private Sub DisplayData(ByVal reader As OleDbDataReader)  
    While reader.Read()  
      For i As Integer = 0 To reader.FieldCount - 1  
        Console.WriteLine("{0} = {1}", _  
         reader.GetName(i), reader.GetValue(i))  
      Next  
      Console.WriteLine("==================================")  
    End While  

  End Sub  
End Module  
using System;  
using System.Data;  
using System.Data.OleDb;  

class Program  
{  
 static void Main()  
 {  
   OleDbDataReader reader =   
     OleDbEnumerator.GetEnumerator(Type.GetTypeFromProgID("MSDAENUM"));  

   DisplayData(reader);  

   Console.WriteLine("Press any key to continue.");  
   Console.ReadKey();  
 }  

 static void DisplayData(OleDbDataReader reader)  
 {  
   while (reader.Read())  
   {  
     for (int i = 0; i < reader.FieldCount; i++)  
     {  
       Console.WriteLine("{0} = {1}",  
        reader.GetName(i), reader.GetValue(i));  
     }  
     Console.WriteLine("==================================");  
   }  
 }  
}  

注解

此方法返回的读取器包含以下列,这些列都包含字符串:The reader that is returned by this method contains the following columns, all of which contain strings:

列序号Column ordinal Column 说明Description
00 SOURCES_NAMESOURCES_NAME 本机 OLE DB 数据源或枚举器的固定名称。The invariant name of the native OLE DB data source or enumerator.
11 SOURCES_PARSENAMESOURCES_PARSENAME 可使用本机 COM 接口 IParseDisplayName 转换为名字对象的用户可读名称。A human-readable name that can be converted to a moniker by using the native COM interface IParseDisplayName. 对应于本机 OLE DB 源行集返回的 SOURCES_PARSENAME 列。Corresponds to the SOURCES_PARSENAME column returned by the native OLE DB sources rowset.
22 SOURCES_DESCRIPTIONSOURCES_DESCRIPTION 本机 OLE DB 数据源的说明。Description of the native OLE DB data source. 对应于本机 OLE DB 源行集返回的 SOURCES_DESCRIPTION 列。Corresponds to the SOURCES_DESCRIPTION column returned by the native OLE DB sources rowset.
33 SOURCES_TYPESOURCES_TYPE 以下枚举成员之一:联编 (0) ,DataSource_MDP (1) DataSource_TDP () (,枚举器) 3。One of the following enumeration members: Binder (0), DataSource_MDP (1), DataSource_TDP (2), Enumerator (3). 这些值对应于本机 OLE DB 源行集的 SOURCES_TYPE 列中返回的值。These correspond to the values returned in the SOURCES_TYPE column of the native OLE DB sources rowset.
44 SOURCES_ISPARENTSOURCES_ISPARENT 仅适用于枚举数。Applicable to enumerators only. 如果为 true ,则指示该条目适用于在其上调用了 GetSourcesRowset 的同一个枚举器,这意味着它也包含在子枚举中。If true, indicates that the entry applies to the same enumerator on which GetSourcesRowset was called, implying that it is also included in the sub-enumeration. 对应于本机 OLE DB 源行集的 SOURCES_ISPARENT 列Corresponds to the SOURCES_ISPARENT column of the native OLE DB sources rowset

OLE DB 提供多个枚举器组件,包括 MSDAENUM、MSDASQL 枚举器、SQLNCLI.MSI 枚举器、SQLOLEDB 枚举器和其他。OLE DB provides several enumerator components, including MSDAENUM, MSDASQL Enumerator, SQLNCLI Enumerator, SQLOLEDB Enumerator, and others. 有关枚举器组件以及如何使用它们的详细信息,请参阅 OLE DB 程序员参考For more information about the enumerator components and how to use them, see the OLE DB Programmer's Reference.

适用于