次の方法で共有


Executables.Add メソッド

新しいコンテナー オブジェクトまたはタスク オブジェクトを Executables コレクションに追加します。

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

構文

'宣言
Public Function Add ( _
    moniker As String _
) As Executable
'使用
Dim instance As Executables 
Dim moniker As String 
Dim returnValue As Executable 

returnValue = instance.Add(moniker)
public Executable Add(
    string moniker
)
public:
Executable^ Add(
    String^ moniker
)
member Add : 
        moniker:string -> Executable
public function Add(
    moniker : String
) : Executable

パラメーター

  • moniker
    型: System.String
    実行可能オブジェクトのモニカーです。

戻り値

型: Microsoft.SqlServer.Dts.Runtime.Executable

新しく作成された Executable オブジェクトからの TaskHost オブジェクトです。新しいオブジェクトのプロパティの設定またはメソッドの呼び出しを行う場合、2 つのオプションを使用できます。

  1. TaskHostProperties コレクションを使用します。 たとえば、オブジェクトからプロパティを取得するには、th.Properties["propertyname"].GetValue(th)) を使用します。 プロパティを設定するには、th.Properties["propertyname"].SetValue(th, <value>); を使用します。

  2. TaskHostInnerObject をタスク クラスにキャストします。 たとえば、一括挿入タスクが Executable としてパッケージに追加され、その後 TaskHost にキャストされた後で、このタスクを BulkInsertTask にキャストするには、BulkInsertTask myTask = th.InnerObject as BulkInsertTask; を使用します。

タスク固有のクラスにキャストせずに TaskHost クラスをコード内で使用する場合、次の利点があります。

  • TaskHost Properties プロバイダーで、コードのアセンブリへの参照が不要です。

  • コンパイル時にタスクの名前を知る必要がないため、すべてのタスクで動作する汎用ルーチンをコーディングできます。 これらの汎用ルーチンでは、タスク名を引数として受け取るメソッドを記述できます。このメソッド コードはすべてのタスクで動作します。 これは、テスト コードを記述するのに適したメソッドです。

TaskHost からタスク固有のクラスにキャストする場合、次の利点があります。

  • Visual Studio プロジェクトで入力候補機能 (IntelliSense) を使用できます。

  • コードの実行が高速化する場合があります。

  • 事前バインドのオブジェクトが生成されます。事前バインドおよび遅延バインドの詳細については、「Visual Basic Language Concepts」の「Early and Late Binding」を参照してください。

必要に応じてオブジェクトをタスク固有のクラスにキャストするかどうかを選択できます。

説明

新しいコンテナーまたはタスクを作成して Executables コレクションに追加する場合は、Add を使用します。 このメソッドのパラメーターは文字列であり、TaskInfo オブジェクトの CLSID、PROGID、STOCK モニカー、または CreationName プロパティを指定できます。 このメソッドは、Executable オブジェクトとして新しく作成されたタスクの TaskHost オブジェクトを返します。 詳細については、「制御フローのタスクまたはコンテナーを追加または削除する」を参照してください。

使用例

次のコード例では、一括挿入タスクを実行可能オブジェクトとしてパッケージに追加します。

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

namespace Executables_API
{
        class Program
        {
        static void Main(string[] args)
        {
            Package pkg = new Package();
            Executable exec = pkg.Executables.Add("STOCK:BulkInsertTask");

            // Obtain the collection.
            Executables pgkExecs = pkg.Executables;
            foreach (Executable eachExec in pgkExecs)
            {
                TaskHost th = exec as TaskHost;
                Console.WriteLine("Executable creation name is: {0}", th.CreationName);
            }
                        // Show that at least one executable exists.
            if (pgkExecs.Contains(0))
            {
                Console.WriteLine("Contains returned true");
            }
            else
            {
                Console.WriteLine("Contains returned false");
            }
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
 
Namespace Executables_API
        Class Program
        Shared  Sub Main(ByVal args() As String)
            Dim pkg As Package =  New Package() 
            Dim exec As Executable =  pkg.Executables.Add("STOCK:BulkInsertTask") 
 
            ' Obtain the collection.
            Dim pgkExecs As Executables =  pkg.Executables 
            Dim eachExec As Executable
            For Each eachExec In pgkExecs
                Dim th As TaskHost =  exec as TaskHost 
                Console.WriteLine("Executable creation name is: {0}", th.CreationName)
            Next
                        ' Show that at least one executable exists.
            If pgkExecs.Contains(0) Then
                Console.WriteLine("Contains returned true")
            Else 
                Console.WriteLine("Contains returned false")
            End If
        End Sub
        End Class
End Namespace

サンプル出力:

Executable creation name is: Microsoft.SqlServer.Dts.Tasks.BulkInsertTask.BulkInsertTask, Microsoft.SqlServer.BulkInsertTask, Version=10.0.000.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91

Contains returned true

関連項目

参照

Executables クラス

Microsoft.SqlServer.Dts.Runtime 名前空間