Partager via


MoveNext méthode

Advances the enumerator to the next element of the collection.

Espace de noms :  Microsoft.SqlServer.Dts.Runtime
Assembly :  Microsoft.SqlServer.ManagedDTS (dans Microsoft.SqlServer.ManagedDTS.dll)

Syntaxe

'Déclaration
Public Function MoveNext As Boolean
'Utilisation
Dim instance As DtsEnumerator
Dim returnValue As Boolean

returnValue = instance.MoveNext()
public bool MoveNext()
public:
virtual bool MoveNext() sealed
abstract MoveNext : unit -> bool 
override MoveNext : unit -> bool 
public final function MoveNext() : boolean

Valeur de retour

Type : System. . :: . .Boolean
true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.

Implémente

IEnumerator. . :: . .MoveNext() () () ()

Notes

After an enumerator is created or after a call to the Reset method, an enumerator is positioned before the first element of the collection, and the first call to MoveNext moves the enumerator over the first element of the collection.

After the end of the collection is passed, subsequent calls to MoveNext return false until Reset is called.

An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and the next call to MoveNext or Reset throws an InvalidOperationException.

Exemples

The following code example adds a task to a package then runs the package. The warnings collection is created by creating a WarningEnumerator, which inherits from this DtsEnumerator class, and displays each warning description using Current and MoveNext methods to review the warnings in the collection.

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

Sample Output:

Package warnings count before running: 0

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

Package warnings count after running the package: 2

The collection contains the following values:

[0] The address in the From line is not formed correctly. It is missing an @ or it is not valid.

[1] Subject is empty