Share via


DtsEnumerator.Current 属性

定义

获取集合中的当前元素。

public:
 property System::Object ^ Current { System::Object ^ get(); };
public object Current { get; }
member this.Current : obj
Public ReadOnly Property Current As Object

属性值

集合中的当前元素。

实现

示例

下面的代码示例将任务添加到包,然后运行包。 通过创建一个WarningEnumerator从此类DtsEnumerator继承的警告集合来创建警告集合,并显示每个警告说明以及CurrentMoveNext用于查看集合中的警告的方法。

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

namespace Microsoft.SqlServer.SSIS.Samples  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Package package = new Package();  
            Console.WriteLine("Package warnings count before running: {0}", package.Warnings.Count);  

            TaskHost taskH2 = (TaskHost)package.Executables.Add("STOCK:SendMailTask");  
            taskH2.FailPackageOnFailure = false;  
            taskH2.FailParentOnFailure = false;  
            Console.WriteLine("SendMailTask: {0}", taskH2.ID);  

            // Test that warnings were successfully added to the collection.  
            package.MaximumErrorCount = 100;  
            package.FailPackageOnFailure = false;  
            package.FailParentOnFailure = false;  
            package.DelayValidation = true;  
            package.Execute();  

            Console.WriteLine("Package warnings count after running the package: {0}", package.Warnings.Count);  

            // Create the enumerator.  
            WarningEnumerator myEnumerator = package.Warnings.GetEnumerator();  
            Console.WriteLine("The collection contains the following values:");  
            int i = 0;  
            while ((myEnumerator.MoveNext()) && (myEnumerator.Current != null))  
                Console.WriteLine("[{0}] {1}", i++, myEnumerator.Current.Description);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  
Imports Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask  

Namespace Microsoft.SqlServer.SSIS.Samples  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim package As Package =  New Package()   
            Console.WriteLine("Package warnings count before running: {0}", package.Warnings.Count)  

            Dim taskH2 As TaskHost = CType(package.Executables.Add("STOCK:SendMailTask"), TaskHost)  
            taskH2.FailPackageOnFailure = False  
            taskH2.FailParentOnFailure = False  
            Console.WriteLine("SendMailTask: {0}", taskH2.ID)  

            ' Test that warnings were successfully added to the collection.  
            package.MaximumErrorCount = 100  
            package.FailPackageOnFailure = False  
            package.FailParentOnFailure = False  
            package.DelayValidation = True  
            package.Execute()  

            Console.WriteLine("Package warnings count after running the package: {0}", package.Warnings.Count)  

            ' Create the enumerator.  
            Dim myEnumerator As WarningEnumerator =  package.Warnings.GetEnumerator()   
            Console.WriteLine("The collection contains the following values:")  
            Dim i As Integer =  0   
            While (myEnumerator.MoveNext()) &&(myEnumerator.Current <> Nothing)  
                Console.WriteLine("[{0}] {1}",i = Console.WriteLine("[{0}] {1}",i + 1  
            End While  
        End Sub  
    End Class  
End Namespace  

示例输出:

运行前的包警告计数:0

SendMailTask: {34CAEFF9-64BF-401D-B646-C88B705DB971}

运行包后包警告计数:2

集合包含以下值:

[0] “发件人”行中的地址未正确形成。 缺少 @ 或无效。

[1] 主题为空

注解

创建枚举器或调用 Reset 方法后, MoveNext 必须调用该方法,才能在读取值 Current之前将枚举器提升到集合的第一个元素;否则为 Current 未定义。

Current如果最后一次调用返回MoveNextfalse,则也会引发异常,该调用指示集合的末尾。

Current不会移动枚举器的位置,因此,在调用或调用之前MoveNextReset,要Current返回同一对象的连续调用。

只要集合保持不变,枚举器就仍有效。 如果对集合进行了更改(例如添加、修改或删除元素),则枚举器将不可恢复地失效,下次调用 MoveNextReset 引发该 InvalidOperationException调用。 如果在 MoveNextCurrent 之间修改集合,那么即使枚举数已经无效,Current 也将返回它所设置成的元素。

适用于