次の方法で共有


MoveNext メソッド

コレクションの次の要素に列挙子を進めます。

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

構文

'宣言
Public Function MoveNext As Boolean
'使用
Dim instance As SMOEnumerator
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

戻り値

型: System. . :: . .Boolean
次の要素に列挙子が正常に進んだ場合は true、列挙子がコレクションの末尾に達している場合は false です。

実装

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

使用例

次のコード例では、ForEachLoop と SMO 列挙子を作成し、SMO 列挙子を ForEachEnumeratorHost でホストして、ForEachEnumerator として ForEachLoop に追加します。ForEachSMOEnumerator が返され、SMOEnumerator を System.Collections.IEnumerator として作成し、MoveNext と Current を使用して繰り返し処理します。コレクションの末尾を越えたら、Reset を使用して、反復子をリセットします。

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Runtime.Enumerators.SMO;

namespace SMOEnumerator
{
    class Program
    {
        const string PACKAGEFILENAME = @"\SamplePackage.dtsx";

        static void Main(string[] args)
        {
            // Create the SSIS application
            Application application = new Application();

            // Create the new package
            Package package = new Package();
            package.PackageType = DTSPackageType.DTSDesigner100;
            package.Name = "SMOEnumerator Sample";
            package.Description = "This is a sample for SMOEnumerator";
            package.CreatorComputerName = @"MACHINENAME"; // System.Environment.MachineName;
            package.CreatorName = @"USERNAME"; //System.Environment.UserName;

            // Adds the ADO.NET connection manager to the package
            Connections connections = package.Connections;
            ConnectionManager connectionManager = connections.Add("ADO.NET:SQL");
            Console.WriteLine("ConnectionManager creation name: {0}", connectionManager.CreationName);
            connectionManager.Name = @"localhost.AdventureWorks2008R2";
            connectionManager.ConnectionString = @"Data Source=localhost;"
                + "Initial Catalog=AdventureWorks2008R2;"
                + "Integrated Security=True;";

            // Create ForEach SMO Loop task
            Executables executables = package.Executables;
            ForEachLoop forEachLoop = executables.Add("STOCK:FOREACHLOOP") as ForEachLoop;
            forEachLoop.Name = "Foreach Loop Container";
            forEachLoop.Description = "Foreach Loop Container";

            ForEachEnumeratorInfo forEachEnumeratorInfo = application.ForEachEnumeratorInfos["Foreach SMO Enumerator"];
            ForEachEnumeratorHost forEachEnumeratorHost = forEachEnumeratorInfo.CreateNew();
            forEachLoop.ForEachEnumerator = forEachEnumeratorHost;

            // Setup the SMO enumerator
            ForEachSMOEnumerator forEachSMOEnumerator = forEachEnumeratorHost.InnerObject as ForEachSMOEnumerator;
            forEachSMOEnumerator.EnumURN = @"RuntimeServer[@Connection='"
                + connectionManager.ID + @"']/Server[@Name='localhost']"
                + @"/Database[@Name='AdventureWorks2008R2']"
                + @"/SMOEnumObj[@Name='Tables']"
                + @"/SMOEnumType[@Name='ObjectsPP']";

            System.Collections.IEnumerator smoEnumerator = (System.Collections.IEnumerator)forEachSMOEnumerator.GetEnumerator(
            connections, null, null, null);
            Console.WriteLine("The collection contains the following values:");
            int i = 0;
            while ((smoEnumerator.MoveNext()) && (smoEnumerator.Current != null))
                Console.WriteLine("[{0}] {1}", i++, smoEnumerator.Current);

             smoEnumerator.Reset();

            // Validate the layout of the package
            DTSExecResult status = package.Validate(package.Connections, null, null, null);
            Console.WriteLine("Validation result: " + status);

            // Save the package
            String currentDirectory = Environment.CurrentDirectory;
            application.SaveToXml(currentDirectory + PACKAGEFILENAME, package, null);
            Console.WriteLine(@"Package saved to " + currentDirectory + PACKAGEFILENAME);
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Runtime.Enumerators.SMO
 
Namespace SMOEnumerator
    Class Program
        const String PACKAGEFILENAME = "\SamplePackage.dtsx"
 
        Shared  Sub Main(ByVal args() As String)
            ' Create the SSIS application
            Dim application As Application =  New Application() 
 
            ' Create the new package
            Dim package As Package =  New Package() 
            package.PackageType = DTSPackageType.DTSDesigner100
            package.Name = "SMOEnumerator Sample"
            package.Description = "This is a sample for SMOEnumerator"
            package.CreatorComputerName = "MACHINENAME" ' System.Environment.MachineName;
            package.CreatorName = "USERNAME" 'System.Environment.UserName;
 
            ' Adds the ADO.NET connection manager to the package
            Dim connections As Connections =  package.Connections 
            Dim connectionManager As ConnectionManager =  connections.Add("ADO.NET:SQL") 
            Console.WriteLine("ConnectionManager creation name: {0}", connectionManager.CreationName)
            connectionManager.Name = "localhost.AdventureWorks2008R2"
            connectionManager.ConnectionString = "Data Source=localhost;"
                + "Initial Catalog=AdventureWorks2008R2;"
                Dim "Integrated Security=True;" As +
 
            ' Create ForEach SMO Loop task
            Dim executables As Executables =  package.Executables 
            Dim forEachLoop As ForEachLoop =  executables.Add("STOCK:FOREACHLOOP") as ForEachLoop 
            forEachLoop.Name = "Foreach Loop Container"
            forEachLoop.Description = "Foreach Loop Container"
 
            Dim forEachEnumeratorInfo As ForEachEnumeratorInfo =  application.ForEachEnumeratorInfos("Foreach SMO Enumerator") 
            Dim forEachEnumeratorHost As ForEachEnumeratorHost =  forEachEnumeratorInfo.CreateNew() 
            forEachLoop.ForEachEnumerator = forEachEnumeratorHost
 
            ' Setup the SMO enumerator
            Dim forEachSMOEnumerator As ForEachSMOEnumerator =  forEachEnumeratorHost.InnerObject as ForEachSMOEnumerator 
            forEachSMOEnumerator.EnumURN = "RuntimeServer[@Connection='"
                + connectionManager.ID + "']/Server[@Name='localhost']"
                + "/Database[@Name='AdventureWorks2008R2']"
                + "/SMOEnumObj[@Name='Tables']"
                Dim "/SMOEnumType[@Name='ObjectsPP']" As +
 
            System.Collections.IEnumerator smoEnumerator = (System.Collections.IEnumerator)forEachSMOEnumerator.GetEnumerator(
                connections, Nothing, Nothing, Nothing)
            Console.WriteLine("The collection contains the following values:")
            Dim i As Integer =  0 
            While (smoEnumerator.MoveNext()) &&(smoEnumerator.Current <> Nothing)
            Console.WriteLine("[{0}] {1}",i = Console.WriteLine("[{0}] {1}",i + 1
            End While
 
             smoEnumerator.Reset()
 
            ' Validate the layout of the package
            Dim status As DTSExecResult =  package.Validate(package.Connections,Nothing,Nothing,Nothing) 
            Console.WriteLine("Validation result: " + status)
 
            ' Save the package
            Dim currentDirectory As String =  Environment.CurrentDirectory 
            application.SaveToXml(currentDirectory + PACKAGEFILENAME, package, Nothing)
            Console.WriteLine("Package saved to " + currentDirectory + PACKAGEFILENAME)
        End Sub
    End Class
End Namespace