TaskHost.SetExpression(String, String) 方法

定義

將指定的運算式指派至屬性。 指定 null 可從屬性中移除現有的運算式。

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)

參數

propertyName
String

要指派運算式的目標屬性名稱。

expression
String

運算式。

實作

範例

下列程式碼範例顯示如何使用的 SetExpressionGetExpression 方法 TaskHost 。 在此程式碼範例中,主控的工作是 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);  
        }  
    }  
}  

範例輸出:

CheckConstraints 的原始值: False

CheckConstraints 的新值: True

CheckConstraints 的運算式: true

備註

propertyName可以是物件上任何可用的屬性。

適用於