Redigera

Dela via


OleDbEnumerator.GetEnumerator(Type) Method

Definition

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

Parameters

type
Type

A Type.

Returns

An OleDbDataReader that contains information about the requested OLE DB providers, using the specified OLE DB enumerator.

Exceptions

The provider does not support ISourcesRowset.

An exception has occurred in the underlying provider.

Examples

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("==================================");  
   }  
 }  
}  

Remarks

The reader that is returned by this method contains the following columns, all of which contain strings:

Column ordinal Column Description
0 SOURCES_NAME The invariant name of the native OLE DB data source or enumerator.
1 SOURCES_PARSENAME A human-readable name that can be converted to a moniker by using the native COM interface IParseDisplayName. Corresponds to the SOURCES_PARSENAME column returned by the native OLE DB sources rowset.
2 SOURCES_DESCRIPTION Description of the native OLE DB data source. Corresponds to the SOURCES_DESCRIPTION column returned by the native OLE DB sources rowset.
3 SOURCES_TYPE One of the following enumeration members: Binder (0), DataSource_MDP (1), DataSource_TDP (2), Enumerator (3). These correspond to the values returned in the SOURCES_TYPE column of the native OLE DB sources rowset.
4 SOURCES_ISPARENT Applicable to enumerators only. 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. Corresponds to the SOURCES_ISPARENT column of the native OLE DB sources rowset

OLE DB provides several enumerator components, including MSDAENUM, MSDASQL Enumerator, SQLNCLI Enumerator, SQLOLEDB Enumerator, and others. For more information about the enumerator components and how to use them, see the OLE DB Programmer's Reference.

Applies to