Compartir a través de


Configurations.Remove(Object) Método

Definición

Quita un objeto Configuration de la colección Configurations.

public:
 void Remove(System::Object ^ index);
public void Remove (object index);
member this.Remove : obj -> unit
Public Sub Remove (index As Object)

Parámetros

index
Object

El nombre, el índice, el identificador o la identidad del objeto Configuration que se va a quitar.

Ejemplos

En el ejemplo de código siguiente se crean tres configuraciones y se agregan a un paquete. A continuación, muestra su nombre y los nombres se muestran en el orden en que se agregaron. Con el Remove método , se quita la configuración en la segunda posición, la posición de índice 1. Los nombres se vuelven a mostrar y Conf2 ya no están en la colección.

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

namespace Configurations_API  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Package p = new Package();  

            Configuration conf1 = p.Configurations.Add();  
            conf1.ConfigurationString = "Conf1 Configuration String";  
            conf1.ConfigurationType = DTSConfigurationType.EnvVariable;  
            conf1.Description = "Some description for Conf1 configuration";  
            conf1.Name = "Conf1";  
            conf1.PackagePath = "A Variable Name in configuration Conf1";  

            Configuration conf2 = p.Configurations.Add();  
            conf2.ConfigurationString = "Conf2 Configuration String";  
            conf2.ConfigurationType = DTSConfigurationType.ConfigFile;  
            conf2.Description = "Some description for Conf2 configuration";  
            conf2.Name = "Conf2";  
            conf2.PackagePath = "A Variable Name in configuration Conf2";  

            Configuration conf3 = p.Configurations.Add();  
            conf3.ConfigurationString = "Conf3 Configuration String2";  
            conf3.ConfigurationType = DTSConfigurationType.RegEntry;  
            conf3.Description = "Conf3 description for Conf3 configuration2";  
            conf3.Name = "Conf3";  
            conf3.PackagePath = "A Variable Name in configuration Conf3";  

            DTSExecResult pkgExecResults = p.Execute();  

            if (pkgExecResults == DTSExecResult.Success)  
            {  
                Console.WriteLine("Success!");  
                // Iterate over the configurations.  
                Configurations configs = p.Configurations;  
                foreach (Configuration config in configs)  
                {  
                    // This is an ordered collection, they display in the order added.  
                    Console.WriteLine("Configuration Name {0}", config.Name);  
                }  
                Console.WriteLine("---------------------------------------------------");  

                // Remove Conf2, located in index position 1  
                p.Configurations.Remove(1);  

                foreach (Configuration config in configs)  
                {  
                    Console.WriteLine("Configuration Name {0}", config.Name);  
                }  
                Console.WriteLine("---------------------------------------------------");  
            }  
            else  
            {  
                Console.WriteLine("Results were {0}", pkgExecResults);  
            }  
            Console.WriteLine("Number of configuration in package {0}", p.Configurations.Count);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace Configurations_API  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim p As Package =  New Package()   

            Dim conf1 As Configuration =  p.Configurations.Add()   
            conf1.ConfigurationString = "Conf1 Configuration String"  
            conf1.ConfigurationType = DTSConfigurationType.EnvVariable  
            conf1.Description = "Some description for Conf1 configuration"  
            conf1.Name = "Conf1"  
            conf1.PackagePath = "A Variable Name in configuration Conf1"  

            Dim conf2 As Configuration =  p.Configurations.Add()   
            conf2.ConfigurationString = "Conf2 Configuration String"  
            conf2.ConfigurationType = DTSConfigurationType.ConfigFile  
            conf2.Description = "Some description for Conf2 configuration"  
            conf2.Name = "Conf2"  
            conf2.PackagePath = "A Variable Name in configuration Conf2"  

            Dim conf3 As Configuration =  p.Configurations.Add()   
            conf3.ConfigurationString = "Conf3 Configuration String2"  
            conf3.ConfigurationType = DTSConfigurationType.RegEnTry  
            conf3.Description = "Conf3 description for Conf3 configuration2"  
            conf3.Name = "Conf3"  
            conf3.PackagePath = "A Variable Name in configuration Conf3"  

            Dim pkgExecResults As DTSExecResult =  p.Execute()   

            If pkgExecResults = DTSExecResult.Success Then  
                Console.WriteLine("Success!")  
                ' Iterate over the configurations.  
                Dim configs As Configurations =  p.Configurations   
                Dim config As Configuration  
                For Each config In configs  
                    ' This is an ordered collection, they display in the order added.  
                    Console.WriteLine("Configuration Name {0}", config.Name)  
                Next  
                Console.WriteLine("---------------------------------------------------")  

                ' Remove Conf2, located in index position 1  
                p.Configurations.Remove(1)  

                Dim config As Configuration  
                For Each config In configs  
                    Console.WriteLine("Configuration Name {0}", config.Name)  
                Next  
                Console.WriteLine("---------------------------------------------------")  
            Else   
                Console.WriteLine("Results were {0}", pkgExecResults)  
            End If  
            Console.WriteLine("Number of configuration in package {0}", p.Configurations.Count)  
        End Sub  
    End Class  
End Namespace  

Salida del ejemplo:

La operación se ha realizado correctamente.

Nombre de configuración Conf1

Nombre de configuración Conf2

Nombre de configuración Conf3

---------------------------------------------------

Nombre de configuración Conf1

Nombre de configuración Conf3

---------------------------------------------------

Número de configuración en el paquete 2

Se aplica a