Executables.Add(String) 方法

定义

将新的容器或任务对象添加到 Executables 集合。

public:
 Microsoft::SqlServer::Dts::Runtime::Executable ^ Add(System::String ^ moniker);
public Microsoft.SqlServer.Dts.Runtime.Executable Add (string moniker);
member this.Add : string -> Microsoft.SqlServer.Dts.Runtime.Executable
Public Function Add (moniker As String) As Executable

参数

moniker
String

可执行文件的名字对象。

返回

TaskHost新创建的Executable对象的对象。若要设置属性或调用新对象的方法,有两个选项:使用Properties集合TaskHost。 例如,若要从对象获取属性,请使用 th.Properties[“propertyname”]。GetValue (th) ) 。 若要设置属性,请使用 th.Properties[“propertyname”]。setValue (th,<value>) ;。将InnerObjectTaskHost任务类强制转换为任务类。 例如,若要将大容量插入任务 BulkInsertTask 作为包添加到包 Executable 后将其强制转换为包,然后转换为 a TaskHost,请使用 BulkInsertTask myTask = th。InnerObject 作为 BulkInsertTask;。 TaskHost 在代码中使用类而不强制转换为特定于任务的类具有以下优势: TaskHostProperties 提供程序不需要对代码中的程序集进行引用。 您可以编写适用于任何任务的通用例程,因为您无需在编译时知道任务的名称。 这些通用例程可以是一些方法,其中,您向方法传递任务的名称,因此方法代码适用于所有任务。 这是编写测试代码的好方法。从 TaskHost 任务特定的类转换具有以下优势:Visual Studio 项目提供语句完成 (IntelliSense) 。 代码的运行速度可能会更快。 生成早期绑定对象。有关早期绑定和后期绑定的详细信息,请参阅 Visual Basic 语言概念中的早期和后期绑定。根据需求,你可能或可能不会将对象强制转换为其特定于任务的类。

示例

下面的代码示例将大容量插入任务作为可执行文件添加到包中。

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使用Add。 方法参数是一个字符串,可以是对象的 CLSID、PROGID、STOCK 名字对象或 CreationName 属性 TaskInfo 。 该方法将 TaskHost 新创建的任务的对象作为对象 Executable 返回。 有关详细信息,请参阅 在控制流中添加或删除任务或容器

适用于