다음을 통해 공유


DtsWarnings.Contains(Object) 메서드

정의

예외를 throw하지 않고 인덱싱을 사용하여 컬렉션의 항목에 액세스할 수 있는지 여부를 나타내는 부울을 반환합니다.

public:
 bool Contains(System::Object ^ index);
public bool Contains (object index);
member this.Contains : obj -> bool
Public Function Contains (index As Object) As Boolean

매개 변수

index
Object

컬렉션에서 찾을 이름, ID 또는 인덱스입니다.

반환

이름, ID 또는 인덱스로 컬렉션에 액세스할 수 있는지 여부를 나타내는 부울입니다. true 값은 DtsWarnings[index]구문을 사용하여 컬렉션에 액세스할 수 있음을 나타냅니다. false 값은 인덱싱을 사용하여 컬렉션에서 항목을 검색할 수 없음을 DtsWarnings 나타냅니다.

예제

다음 코드 예제에서는 메일 보내기 작업을 만들고 패키지에 추가합니다. 메일 보내기 태스크의 모든 필수 속성이 설정되지 않으므로 패키지가 실행되면 컬렉션과 컬렉션에 오류 및 DtsWarnings 경고가 DtsErrors 발생합니다. 이 Contains 메서드는 구문을 사용하여 DtsWarnings[index] 컬렉션에 액세스할 수 있는지 확인하는 데 사용되며, 이 경우 해당 구문을 사용하여 일부 속성을 가져옵니다.

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

namespace Microsoft.SqlServer.SSIS.Samples  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Package package = new Package();  
            TaskHost taskH2 = (TaskHost)package.Executables.Add("STOCK:SendMailTask");  
            taskH2.FailPackageOnFailure = false;  
            taskH2.FailParentOnFailure = false;  
            Console.WriteLine("SendMailTask: {0}", taskH2.ID);  

            package.MaximumErrorCount = 100;  
            package.FailPackageOnFailure = false;  
            package.FailParentOnFailure = false;  
            package.DelayValidation = true;  
            package.Execute();  

            // Get the collections.  
            DtsWarnings dtsWarns = package.Warnings;  
            DtsErrors dtsErrs = package.Errors;  
            // Use Contains to see if collection can be accessed  
            // using item syntax of [x].  
            Boolean warnItem = dtsWarns.Contains(0);  
            Boolean errItem = dtsErrs.Contains(0);  

            // If item sytax can be used, use it to obtain information.  
            if (warnItem)  
            {  
            //Using the Item method syntax of [x], obtain the first entry and a description.  
            DtsWarning firstWItem = dtsWarns[0];  
            String nameOfFirstItem = dtsWarns[0].SubComponent;  

            //Print the subcomponent for the warning located at position [0] two ways.  
            Console.WriteLine("The first warning subcomponent is: {0}", firstWItem.SubComponent);  
            Console.WriteLine("The first warning subcomponent is: {0}", nameOfFirstItem);  
            }  

            // If item sytax can be used, use it to obtain information.  
            if (errItem)  
            {  
            //Using the Item method syntax of [x], obtain the first entry and a description.  
            DtsError firstEItem = dtsErrs[0];  
            String nameOfFirstItem = dtsErrs[0].Description;  

            //Print the description of the warning located at position [0] two ways.  
            Console.WriteLine("The first error description is: {0}", firstEItem.Description);  
            Console.WriteLine("The first error description is: {0}", nameOfFirstItem);  
            }  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  
Imports Microsoft.SqlServer.Dts.Tasks.SendMailTask  

Namespace Microsoft.SqlServer.SSIS.Samples  
    Class Program  
        static void Main(string() args)  
        {  
            Dim package As Package =  New Package()   
            Dim taskH2 As TaskHost = CType(package.Executables.Add("STOCK:SendMailTask"), TaskHost)  
            taskH2.FailPackageOnFailure = False  
            taskH2.FailParentOnFailure = False  
            Console.WriteLine("SendMailTask: {0}", taskH2.ID)  

            package.MaximumErrorCount = 100  
            package.FailPackageOnFailure = False  
            package.FailParentOnFailure = False  
            package.DelayValidation = True  
            package.Execute()  

            ' Get the collections.  
            Dim dtsWarns As DtsWarnings =  package.Warnings   
            Dim dtsErrs As DtsErrors =  package.Errors   
            ' Use Contains to see if collection can be accessed  
            ' using item syntax of [x].  
            Dim warnItem As Boolean =  dtsWarns.Contains(0)   
            Dim errItem As Boolean =  dtsErrs.Contains(0)   

            ' If item sytax can be used, use it to obtain information.  
            if (warnItem)  
            {  
            'Using the Item method syntax of [x], obtain the first entry and a description.  
            Dim firstWItem As DtsWarning =  dtsWarns(0)   
            Dim nameOfFirstItem As String =  dtsWarns(0).SubComponent   

            'Print the subcomponent for the warning located at position [0] two ways.  
            Console.WriteLine("The first warning subcomponent is: {0}", firstWItem.SubComponent)  
            Console.WriteLine("The first warning subcomponent is: {0}", nameOfFirstItem)  
            }  

            ' If item sytax can be used, use it to obtain information.  
            if (errItem)  
            {  
            'Using the Item method syntax of [x], obtain the first entry and a description.  
            Dim firstEItem As DtsError =  dtsErrs(0)   
            Dim nameOfFirstItem As String =  dtsErrs(0).Description   

            'Print the description of the warning located at position [0] two ways.  
            Console.WriteLine("The first error description is: {0}", firstEItem.Description)  
            Console.WriteLine("The first error description is: {0}", nameOfFirstItem)  
            }  
        }  
    End Class  
End Namespace  

샘플 출력:

SendMailTask: {12ADD307-23DA-42C9-A4B2-E360DEFD7563}

The first warning subcomponent is: Send Mail Task

The first warning subcomponent is: Send Mail Task

The first error description is: SMTP Server not specified

The first error description is: SMTP Server not specified

적용 대상