Executables.Add Method
Adds a new container or task object to the Executables collection.
命名空间: Microsoft.SqlServer.Dts.Runtime
程序集: Microsoft.SqlServer.ManagedDTS (in microsoft.sqlserver.manageddts.dll)
语法
声明
Public Function Add ( _
moniker As String _
) As Executable
public Executable Add (
string moniker
)
public:
Executable^ Add (
String^ moniker
)
public Executable Add (
String moniker
)
public function Add (
moniker : String
) : Executable
参数
- moniker
The moniker to the executable.
返回值
A TaskHost object from the newly created Executable object. To set properties or to call methods on the new object, you have two options:
Use the Properties collection of the TaskHost. For example, to get a property from the object, use
th.Properties["propertyname"].GetValue(th))
. To set a property, useth.Properties["propertyname"].SetValue(th, <value>);
.Cast the InnerObject of the TaskHost to the task class. For example, to cast the Bulk Insert task to a BulkInsertTask after it has been added to a package as an Executable and subsequently cast to a TaskHost, use
BulkInsertTask myTask = th.InnerObject as BulkInsertTask;
.
Using the TaskHost class in code without casting to the task-specific class has these advantages:
The TaskHostProperties provider does not require a reference to the assembly in the code.
You can code generic routines that work for any task, because you do not have to know the name of the task at compile time. These generic routines can be methods where you pass in the name of the task to the method, and the method code works for all tasks. This is a good method for writing test code.
Casting from the TaskHost to the task-specific class has the following advantages:
The Visual Studio project provides you with statement completion (IntelliSense).
The code may run faster.
Produces early-bound objects For more information on early and late binding, see Early and Late Binding in Visual Basic Language Concepts.
Depending on your needs, you may or may not cast the object to its task-specific class.
备注
Use Add when you create a new container or task and want to add it to the Executables collection. The method parameter is a string, which can be the CLSID, PROGID, STOCK moniker, or CreationName property of the TaskInfo object. The method returns the TaskHost object of the newly created task as an Executable object. For more information, see 将任务添加到控制流.
示例
The following code example adds the Bulk Insert task as an executable to the package.
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
Sample Output:
Executable creation name is: Microsoft.SqlServer.Dts.Tasks.BulkInsertTask.BulkInsertTask, Microsoft.SqlServer.BulkInsertTask, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91
Contains returned true
线程安全
Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
平台
开发平台
有关支持的平台列表,请参阅安装 SQL Server 2005 的硬件和软件要求。
目标平台
有关支持的平台列表,请参阅安装 SQL Server 2005 的硬件和软件要求。
请参阅
参考
Executables Class
Executables Members
Microsoft.SqlServer.Dts.Runtime Namespace