語言

DBProviderInfos.Item[Object] 屬性

定義

從集合中回傳一個 DBProviderInfo 物件。

public:
 property Microsoft::SqlServer::Dts::Runtime::DBProviderInfo ^ default[System::Object ^] { Microsoft::SqlServer::Dts::Runtime::DBProviderInfo ^ get(System::Object ^ index); };
public Microsoft.SqlServer.Dts.Runtime.DBProviderInfo this[object index] { get; }
member this.Item(obj) : Microsoft.SqlServer.Dts.Runtime.DBProviderInfo
Default Public ReadOnly Property Item(index As Object) As DBProviderInfo

參數

index
Object

要回傳物件的 DBProviderInfo 名稱、描述或索引。

屬性值

DBProviderInfos 物件。

範例

以下程式碼範例是利用兩種方法從集合中取得一個項目。 第一種方法是利用語 dbprovInfos[0] 法擷取集合中位於第一位置的整個物件並將其放入物件中 dbInfo 。 你現在可以像平常一樣從物件中取得所有屬性 dbInfo 。 第二種方法示範如何從集合中的第一個物件取得特定屬性。

using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  

namespace DBProvInfos_GetEnum  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Application app = new Application();  
            DBProviderInfos dbprovInfos = app.DBProviderInfos;  

            //Using the Item method syntax of [x], obtain the first entry.  
            DBProviderInfo dbInfo = dbprovInfos[0];  
            String nameOfFirstItem = dbprovInfos[0].Name;  

            //Print the name of the log provider object located at position [0].  
            Console.WriteLine("The db provider type of the first provider is: {0}", dbInfo.ProviderType);  
            Console.WriteLine("The Name of the first database provider is: {0}", nameOfFirstItem);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace DBProvInfos_GetEnum  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim app As Application =  New Application()   
            Dim dbprovInfos As DBProviderInfos =  app.DBProviderInfos   

            'Using the Item method syntax of [x], obtain the first entry.  
            Dim dbInfo As DBProviderInfo =  dbprovInfos(0)   
            Dim nameOfFirstItem As String =  dbprovInfos(0).Name   

            'Print the name of the log provider object located at position [0].  
            Console.WriteLine("The db provider type of the first provider is: {0}", dbInfo.ProviderType)  
            Console.WriteLine("The Name of the first database provider is: {0}", nameOfFirstItem)  
        End Sub  
    End Class  
End Namespace  

範例輸出:

第一個提供者的資料庫提供者類型為:OleDb

第一個資料庫提供者的名稱為:MediaCatalogDB OLE 資料庫提供者

備註

如果呼叫方法 Contains 返回 true,你可以使用語法 DBProviderInfos[index]來存取集合中指定的元素。 若返回 Containsfalse,該屬性會拋出例外。 在 C# 中,這個屬性就是類別的 DBProviderInfos 索引器。

適用於