Share via


TaskHost.SetExpression(String, String) Méthode

Définition

Affecte l'expression spécifiée à la propriété. Spécifiez null pour supprimer une expression existante de la propriété.

public:
 virtual void SetExpression(System::String ^ propertyName, System::String ^ expression);
public void SetExpression (string propertyName, string expression);
abstract member SetExpression : string * string -> unit
override this.SetExpression : string * string -> unit
Public Sub SetExpression (propertyName As String, expression As String)

Paramètres

propertyName
String

Nom de la propriété à laquelle affecter l'expression.

expression
String

Expression.

Implémente

Exemples

L’exemple de code suivant montre comment utiliser les SetExpression méthodes et GetExpression de .TaskHost Pour cet exemple de code, la tâche hébergée est .BulkInsertTask

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

namespace Microsoft.SqlServer.SSIS.Sample  
{  
    class Program  
        {  
        static void Main(string[] args)  
        {  
            Package pkg = new Package();  
            TaskHost th = (TaskHost)pkg.Executables.Add("STOCK:BulkInsertTask");  

            // View information about the CheckConstraints property  
            // before setting it using the SetExpression method.  
            Boolean checkConstraint = (Boolean)th.Properties["CheckConstraints"].GetValue(th);  
            Console.WriteLine("Original value of CheckConstraints: {0}", checkConstraint);  

            // Use SetExpression to set the value to true.  
            String myTrueString = "true";  
            th.Properties["CheckConstraints"].SetExpression(th, myTrueString);  

            // Validate the package to set the expression onto the property.  
            DTSExecResult valResult = pkg.Validate(null, null, null, null);  

            // Retrieve the new value and the expression.  
            checkConstraint = (Boolean)th.Properties["CheckConstraints"].GetValue(th);  
            String myExpression = th.Properties["CheckConstraints"].GetExpression(th);  
            Console.WriteLine("New value of CheckConstraints: {0}", checkConstraint);  
            Console.WriteLine("Expression for CheckConstraints: {0}", myExpression);  
        }  
    }  
}  

Exemple de sortie :

Valeur d’origine de CheckConstraints : False

Nouvelle valeur de CheckConstraints : True

Expression pour CheckConstraints : true

Remarques

peut propertyName être n’importe quelle propriété disponible sur l’objet .

S’applique à