다음을 통해 공유


Variables.Remove Method

Removes a Variable object from the Variables collection.

네임스페이스: Microsoft.SqlServer.Dts.Runtime
어셈블리: Microsoft.SqlServer.ManagedDTS (in microsoft.sqlserver.manageddts.dll)

구문

‘선언
Public Sub Remove ( _
    index As Object _
)
public void Remove (
    Object index
)
public:
void Remove (
    Object^ index
)
public void Remove (
    Object index
)
public function Remove (
    index : Object
)

매개 변수

  • index
    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("");
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
 
Namespace Add_Remove_Vars
    Class Program
        Shared  Sub Main(ByVal args() As String)
            Dim pkg As Package =  New Package() 
            Dim pkgVars As Variables =  pkg.Variables 
            Dim myVar As Variable =  pkg.Variables.Add("myCustomVar",False,"User","3") 
 
            ' Verify whether the variable is in the collection now.
            Dim hasMyVar As Boolean =  pkg.Variables.Contains("myCustomVar") 
            Console.WriteLine("The variable was found? {0}", hasMyVar)
 
            Console.WriteLine("---------------------------")
            ' Loop over the collection using the foreach keyword.
            Dim pkgVar As Variable
            For Each pkgVar In pkgVars
                ' Print variables only from the User namespace.
                If pkgVar.Namespace = "User" Then
                Console.WriteLine("Variable: {0}, {1}", pkgVar.Name, pkgVar.Value.ToString())
                End If
            Next
            Console.WriteLine("---------------------------")
            ' Remove the variable from the namespace.
            pkg.Variables.Remove("myCustomVar")
 
            ' Loop over the collection again.
            Dim pkgVar As Variable
            For Each pkgVar In pkgVars
                ' Print variables only from the User namespace. Nothing should show.
                If pkgVar.Namespace = "User" Then
                    Console.WriteLine("Variable: {0}, {1}", pkgVar.Name, pkgVar.Value.ToString())
                End If
            Next
            Console.WriteLine("---------------------------")
            Console.WriteLine("")
        End Sub
    End Class
End Namespace

Sample Output:

The variable was found? True

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

Variable: myCustomVar, 3

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

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

스레드 보안

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

플랫폼

개발 플랫폼

지원되는 플랫폼 목록은 SQL Server 2005 설치를 위한 하드웨어 및 소프트웨어 요구 사항을 참조하십시오.

대상 플랫폼

지원되는 플랫폼 목록은 SQL Server 2005 설치를 위한 하드웨어 및 소프트웨어 요구 사항을 참조하십시오.

참고 항목

참조

Variables Class
Variables Members
Microsoft.SqlServer.Dts.Runtime Namespace