Linguaggio

Executables.Add(String) Metodo

Definizione

Aggiunge un nuovo contenitore o oggetto task alla Executables collezione.

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

Parametri

moniker
String

Il nome dell'eseguibile.

Valori restituiti

Un TaskHost oggetto proveniente dal nuovo oggetto creato Executable . Per impostare proprietà o chiamare metodi sul nuovo oggetto, hai due opzioni: Usa la Properties collezione del TaskHost. Ad esempio, per ottenere una proprietà dall'oggetto, usa th. Proprietà["nome proprietà"]. GetValue(th)). Per impostare una proprietà, usa th. Proprietà["nome proprietà"]. SetValue(th, <value>);. Lancia il InnerObject del TaskHost per la classe di compito. Ad esempio, per convertire il compito Inserimento in massa su a BulkInsertTask dopo che è stato aggiunto a un pacchetto come un Executable e successivamente cast a TaskHostun , usa BulkInsertTask miTask = th. InnerObject come BulkInsertTask;. L'uso della TaskHost classe in codice senza casting alla classe specifica del compito ha questi vantaggi: Il TaskHostProperties provider non richiede un riferimento all'assembly nel codice. Puoi programmare routine generiche che funzionano per qualsiasi compito, perché non devi conoscere il nome del compito al momento della compilazione. Queste routine generiche possono essere metodi in cui si passa il nome del compito al metodo, e il codice del metodo funziona per tutte le attività. Questo è un buon metodo per scrivere codice di test. Il casting dalla TaskHost classe specifica per compito offre i seguenti vantaggi: Il progetto Visual Studio offre completamento delle istruzioni (IntelliSense). Il codice potrebbe funzionare più velocemente. Produce oggetti legati anticipati Per maggiori informazioni sul binding precoce e tardivo, vedi Binding precoce e tardivo in Visual Basic Language Concepts. A seconda delle tue esigenze, potresti o meno castare l'oggetto nella sua classe specifica per compito.

Esempio

Il seguente esempio di codice aggiunge il compito Inserimento Bulk come eseguibile al pacchetto.

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  

Output di esempio:

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

Commenti

Usalo Add quando crei un nuovo contenitore o compito e vuoi aggiungerlo alla Executables collezione. Il parametro del metodo è una stringa, che può essere il nome CLSID, PROGID, STOCK o CreationName proprietà dell'oggetto TaskInfo . Il metodo restituisce l'oggetto TaskHost del nuovo compito creato come Executable oggetto. Per altre informazioni, vedere Aggiungere o eliminare un'attività o un contenitore in un flusso di controllo.

Si applica a