DtsEventHandlers.Item[Object] Propiedad

Definición

Obtiene un objeto DtsEventHandler de la colección.

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

Parámetros

index
Object

El nombre, el identificador o el índice del objeto DtsEventHandler que se va a devolver de la colección.

Valor de propiedad

Objeto DtsEventHandler de la colección.

Ejemplos

En el ejemplo de código siguiente se recupera la DtsEventHandlers colección y, a continuación, se usa Contains para ver si la sintaxis [x] del elemento se puede usar en la colección.

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

namespace Microsoft.SqlServer.SSIS.Samples  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Package pkg = new Package();  

            // Set up a DtsEventHandler for the OnError event of the package.  
            DtsEventHandler dtsEHOE = (DtsEventHandler)pkg.EventHandlers.Add("OnError");  
            DtsEventHandler dtsEHW = (DtsEventHandler)pkg.EventHandlers.Add("OnWarning");  

            // Create the DtsEventHandlers collection.  
            DtsEventHandlers dtsEHColls = pkg.EventHandlers;  

            // Use the Contains method to see if the item[x] syntax can be used.  
            Boolean dtsContains = dtsEHColls.Contains(0);  
            Console.WriteLine("Item syntax can be used?  {0}", dtsContains);  

            //Using the Item method syntax of [x], obtain the first entry and a name.  
            DtsEventHandler dtsEHFirstEntry = dtsEHColls[0];  
            String nameOfFirstItem = dtsEHColls[0].Name;  

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

Namespace Microsoft.SqlServer.SSIS.Samples  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim pkg As Package =  New Package()   

            ' Set up a DtsEventHandler for the OnError event of the package.  
            Dim dtsEHOE As DtsEventHandler = CType(pkg.EventHandlers.Add("OnError"), DtsEventHandler)  
            Dim dtsEHW As DtsEventHandler = CType(pkg.EventHandlers.Add("OnWarning"), DtsEventHandler)  

            ' Create the DtsEventHandlers collection.  
            Dim dtsEHColls As DtsEventHandlers =  pkg.EventHandlers   

            ' Use the Contains method to see if the item[x] syntax can be used.  
            Dim dtsContains As Boolean =  dtsEHColls.Contains(0)   
            Console.WriteLine("Item syntax can be used?  {0}", dtsContains)  

            'Using the Item method syntax of [x], obtain the first entry and a name.  
            Dim dtsEHFirstEnTry As DtsEventHandler =  dtsEHColls(0)   
            Dim nameOfFirstItem As String =  dtsEHColls(0).Name   

            'Print the name of the log provider object located at position [0].  
            Console.WriteLine("The ID of the first event handler is: {0}", dtsEHFirstEnTry.ID)  
            Console.WriteLine("The Name of the first event handler is: {0}", nameOfFirstItem)  
        End Sub  
    End Class  
End Namespace  

Salida del ejemplo:

¿Se puede usar la sintaxis de elemento? Verdadero

El identificador del primer controlador de eventos es: {4B9E438E-BA17-4A51-8235-3072AFF92F99}

El nombre del primer controlador de eventos es: OnError

Comentarios

Si la llamada al Contains método devuelve true, puede tener acceso al elemento especificado de la colección mediante la sintaxis DtsEventHandlers[index]. Si el Contains método devuelve false, esta propiedad produce una excepción. En C#, esta propiedad es el indizador para la clase DtsEventHandlers.

Se aplica a