Connections.Item[Object] Свойство

Определение

Возвращает объект ConnectionManager из коллекции Connections.

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

Параметры

index
Object

Имя, удостоверение, идентификатор или индекс объекта ConnectionManager, который необходимо вернуть.

Значение свойства

Объект ConnectionManager из коллекции.

Примеры

В следующем примере кода извлекается элемент из коллекции с помощью двух методов. Первый метод использует conns[0] синтаксис, чтобы получить весь объект, расположенный в первой позиции коллекции, и поместить его в myConnMgr переменную. Теперь вы можете получить все свойства из обычной myConnMgr версии. Второй метод извлекает определенное свойство из первого объекта в коллекции с помощью синтаксиса conns[0].<property> .

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

namespace Connections_Item  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            // The package is one of the SSIS Samples.  
            string mySample = @"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx";  

            // Create an application and load the sample.  
            Application app = new Application();  
            Package pkg = app.LoadPackage(mySample, null);  
            Connections conns = pkg.Connections;  

            //Using the Item method syntax of [x], obtain the  
            // entire first entry, and then just the name.  
            ConnectionManager myConnMgr = conns[0];  
            String nameOfFirstItem = conns[0].Name;  

            //Print the name of the connection manager located at position [0].  
            Console.WriteLine("The ID of the first connection info is: {0}", myConnMgr.ID);  
            Console.WriteLine("The Name of the first connection info is: {0}", nameOfFirstItem);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace Connections_Item  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            ' The package is one of the SSIS Samples.  
            Dim mySample As String =  "C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx"   

            ' Create an application and load the sample.  
            Dim app As Application =  New Application()   
            Dim pkg As Package =  app.LoadPackage(mySample,Nothing)   
            Dim conns As Connections =  pkg.Connections   

            'Using the Item method syntax of [x], obtain the  
            ' entire first entry, and then just the name.  
            Dim myConnMgr As ConnectionManager =  conns(0)   
            Dim nameOfFirstItem As String =  conns(0).Name   

            'Print the name of the connection manager located at position [0].  
            Console.WriteLine("The ID of the first connection info is: {0}", myConnMgr.ID)  
            Console.WriteLine("The Name of the first connection info is: {0}", nameOfFirstItem)  
        End Sub  
    End Class  
End Namespace  

Образец вывода:

The ID of the first connection info is: {B52C0D78-5402-4544-BFEC-2BE203900C91}

The Name of the first connection info is: Create_Execute_Process_Dest.sql

Комментарии

Если вызов метода Contains возвращается true, доступ к указанному элементу в коллекции можно получить с помощью синтаксиса Connections[index]. Contains Если метод возвращаетсяfalse, это свойство создает исключение. В C# это свойство является индексатором класса Connections.

Применяется к