共用方式為


DtsWarnings.Contains Method

Returns a Boolean that indicates if the items in the collection can be accessed using indexing without throwing an exception.

命名空間: Microsoft.SqlServer.Dts.Runtime
組件: Microsoft.SqlServer.ManagedDTS (in microsoft.sqlserver.manageddts.dll)

語法

'宣告
Public Function Contains ( _
    index As Object _
) As Boolean
public bool Contains (
    Object index
)
public:
bool Contains (
    Object^ index
)
public boolean Contains (
    Object index
)
public function Contains (
    index : Object
) : boolean

參數

  • index
    The name, identity, or index to locate in the collection.

傳回值

A Boolean that indicates if the collection can be accessed by name, identity, or index. A value of true indicates that the collection can be accessed using the syntax DtsWarnings[index]. A value of false indicates that indexing cannot be used to retrieve items from the DtsWarnings collection.

範例

The following code example creates a Send Mail task and adds it to a package. Not all of the required properties of the Send Mail task are set, so when the package runs, there are errors and warnings in the DtsErrors and DtsWarnings collections. The Contains method is used to see if the collections can be accessed using the DtsWarnings[index] syntax, and if so, obtains some properties using that syntax.

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

Sample Output:

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

執行緒安全性

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 的硬體和軟體需求>。

請參閱

參考

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