Remove Method
Collapse the table of content
Expand the table of content

Variables.Remove Method

Removes a Variable object from the Variables collection.

Namespace:  Microsoft.SqlServer.Dts.Runtime
Assembly:  Microsoft.SqlServer.ManagedDTS (in Microsoft.SqlServer.ManagedDTS.dll)

public void Remove(
	Object index
)

Parameters

index
Type: System.Object
The name, ID, description, or index of the Variable object to remove from the collection.

The following code example adds a variable to an empty package. The variable is named myCustomVar, is given a value of 3, and is located in the User namespace. The variable is then removed using the Remove method.

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

namespace Add_Remove_Vars
{
    class Program
    {
        static void Main(string[] args)
        {
            Package pkg = new Package();
            Variables pkgVars = pkg.Variables;
            Variable myVar = pkg.Variables.Add("myCustomVar", false, "User", "3");

            // Verify whether the variable is in the collection now.
            Boolean hasMyVar = pkg.Variables.Contains("myCustomVar");
            Console.WriteLine("The variable was found? {0}", hasMyVar);

            Console.WriteLine("---------------------------");
            // Loop over the collection using the foreach keyword.
            foreach (Variable pkgVar in pkgVars)
            {
                // Print variables only from the User namespace.
                if (pkgVar.Namespace == "User")
                {
                Console.WriteLine("Variable: {0}, {1}", pkgVar.Name, pkgVar.Value.ToString());
                 }
            }
            Console.WriteLine("---------------------------");
            // Remove the variable from the namespace.
            pkg.Variables.Remove("myCustomVar");

            // Loop over the collection again.
            foreach (Variable pkgVar in pkgVars)
            {
                // Print variables only from the User namespace. Nothing should show.
                if (pkgVar.Namespace == "User")
                {
                    Console.WriteLine("Variable: {0}, {1}", pkgVar.Name, pkgVar.Value.ToString());
                }
            }
            Console.WriteLine("---------------------------");
            Console.WriteLine("");
        }
    }
}

Sample Output:

The variable was found? True

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

Variable: myCustomVar, 3

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

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

Community Additions

ADD
Show:
© 2016 Microsoft