DtsEventHandler.SetExpression(String, String) 方法    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将指定的表达式分配给属性。 指定 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 -> unitPublic Sub SetExpression (propertyName As String, expression As String)参数
- propertyName
- String
向其分配表达式的属性的名称。
- expression
- String
表达式。
实现
示例
下面的代码示例创建包并添加 DtsEventHandler 包 OnError 事件。 
              SetExpression使用该属性,将FailParentOnFailure修改该属性。 使用该方法 GetExpression 时,将显示新值和关联的表达式。
using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  
namespace Microsoft.SqlServer.SSIS.Sample  
{  
    class SSISProgram  
    {  
        static void Main(string[] args)  
        {  
            Package pkg = new Package();  
            // Set up a DtsEventHandler for the package OnError event.  
            DtsEventHandler dtsEH = (DtsEventHandler)pkg.EventHandlers.Add("OnError");  
            // Show the value of DebugMode on the container before modifying it.  
            Console.WriteLine("Original FailParentOnFailure = {0}", dtsEH.FailParentOnFailure);  
            // Use SetExpression to set DebugMode to "true".  
            String myExpression = "True";  
            dtsEH.SetExpression("FailParentOnFailure", myExpression);  
            //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.  
            String myNewExpression = dtsEH.GetExpression("FailParentOnFailure");  
            Console.WriteLine("New value of FailParentOnFailure: {0}", dtsEH.FailParentOnFailure);  
            Console.WriteLine("Expression for FailParentOnFailure: {0}", myNewExpression);  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  
Class SSISProgram  
    Shared Sub Main(ByVal args() As String)   
        Dim pkg As New Package()  
        ' Set up a DtsEventHandler for the package OnError event.  
        Dim dtsEH As DtsEventHandler = CType(pkg.EventHandlers.Add("OnError"), DtsEventHandler)  
        ' Show the value of DebugMode on the container before modifying it.  
        Console.WriteLine("Original FailParentOnFailure = {0}", dtsEH.FailParentOnFailure)  
        ' Use SetExpression to set DebugMode to "true".  
        Dim myExpression As String = "True"  
        dtsEH.SetExpression("FailParentOnFailure", myExpression)  
        'Validate the package to set the expression onto the property.  
        Dim valResult As DTSExecResult = pkg.Validate(Nothing, Nothing, Nothing, Nothing)  
        ' Retrieve the new value and the expression.  
        Dim myNewExpression As String = dtsEH.GetExpression("FailParentOnFailure")  
        Console.WriteLine("New value of FailParentOnFailure: {0}", dtsEH.FailParentOnFailure)  
        Console.WriteLine("Expression for FailParentOnFailure: {0}", myNewExpression)  
    End Sub 'Main  
End Class  
示例输出:
原始 FailParentOnFailure = False
FailParentOnFailure 的新值:True
FailParentOnFailure 的表达式: True