DtsWarnings.Contains メソッド

例外がスローされることなく、インデックスを使用してコレクション内の項目にアクセスできるかどうかを示す Boolean を返します。

名前空間:  Microsoft.SqlServer.Dts.Runtime
アセンブリ:  Microsoft.SqlServer.ManagedDTS (Microsoft.SqlServer.ManagedDTS.dll)

構文

'宣言
Public Function Contains ( _
    index As Object _
) As Boolean
'使用
Dim instance As DtsWarnings 
Dim index As Object 
Dim returnValue As Boolean 

returnValue = instance.Contains(index)
public bool Contains(
    Object index
)
public:
bool Contains(
    Object^ index
)
member Contains : 
        index:Object -> bool
public function Contains(
    index : Object
) : boolean

パラメーター

  • index
    型: System.Object
    コレクション内で検索する名前、ID、またはインデックスです。

戻り値

型: System.Boolean
名前、ID、またはインデックスを使用してコレクションにアクセスできるかどうかを示す Boolean です。値が true の場合は、構文 DtsWarnings[index] でコレクションにアクセスできます。値が false の場合は、インデックスを使用して DtsWarnings コレクションから項目を取得することができません。

使用例

次のコード例では、メール送信タスクを作成し、パッケージに追加します。 メール送信タスクに必要なすべてのプロパティが設定されているわけではないため、パッケージの実行時に DtsErrors コレクションおよび DtsWarnings コレクションでエラーと警告が発生します。 DtsWarnings[index] 構文を使用してコレクションにアクセスできるかどうかを調べるには、Contains メソッドを使用します。コレクションにアクセスできる場合は、この構文を使用して一部のプロパティを取得します。

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

関連項目

参照

DtsWarnings クラス

Microsoft.SqlServer.Dts.Runtime 名前空間