다음을 통해 공유


DtsProperty.SetExpression Method

Assigns the specified expression to the object. Specify null to remove an existing expression from the property.

네임스페이스: Microsoft.SqlServer.Dts.Runtime
어셈블리: Microsoft.SqlServer.ManagedDTS (in microsoft.sqlserver.manageddts.dll)

구문

‘선언
Public Sub SetExpression ( _
    o As Object, _
    expression As String _
)
public void SetExpression (
    Object o,
    string expression
)
public:
void SetExpression (
    Object^ o, 
    String^ expression
)
public void SetExpression (
    Object o, 
    String expression
)
public function SetExpression (
    o : Object, 
    expression : String
)

매개 변수

  • o
    The name of the object to which to assign the expression.
  • expression
    The expression.

주의

All the containers and several additional objects inherit from IDTSPropertiesProvider, which is the interface that provides the GetExpression and SetExpression methods.

The ConnectionManager is one class that inherits from IDTSPropertiesProvider and implements the SetExpression method. The following code example shows how the SetExpression method is used. The expression sets the value of a property that is specific to a connection manager. The properties that are unique to the connection manager are contained in the Properties collection.

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

namespace ConnMgr_Properties_Collection
{
    class Program
    {
        static void Main(string[] args)
        {
            // The package is one of the SSIS Samples.
            string mySample = @"C:\Program Files\Microsoft SQL Server\90\Samples\Integration Services\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx";

            // Create an application and load the sample.
            Application app = new Application();
            Package pkg = app.LoadPackage(mySample, null);
            Connections myConns = pkg.Connections;

            // Get the Properties collection from the connection manager.
            ConnectionManager myConnMgr = myConns[0];
            DtsProperties connProperties = myConnMgr.Properties;

            // View information about the RetainSameConnection property
            // before setting it using the SetExpression method.
            Boolean hasProperty = connProperties.Contains("RetainSameConnection");
            Console.WriteLine("has RetainSameConnection? {0}", hasProperty);
            Object myValue = myConnMgr.Properties["RetainSameConnection"].GetValue(myConnMgr);
            String mySValue = myValue.ToString();
            Console.WriteLine("value before is {0}", mySValue);String myTrueString = "true";

            // Use SetExpression to set the value to true.
            myConnMgr.Properties["RetainSameConnection"].SetExpression(myConnMgr, myTrueString);
            
            // Validate the package to set the expression onto the property.
            DTSExecResult valResult = pkg.Validate(myConns, null, null, null);
            
            // Now that the value has been set, retrieve it.
            myValue = myConnMgr.Properties["RetainSameConnection"].GetValue(myConnMgr);
            mySValue = myValue.ToString();
            Console.WriteLine("value after is {0}", mySValue); 
        }
    }
}
Imports Microsoft.SqlServer.Dts.Runtime
 
Namespace ConnMgr_Properties_Collection
    Class Program
        Shared  Sub Main(ByVal args() As String)
        ' The package is one of the SSIS Samples.
        Dim mySample As String = "C:\Program Files\Microsoft SQL Server\90\Samples\Integration Services\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx"
        
        ' Create an application and load the sample.
        Dim app As New Application()
        Dim pkg As Package = app.LoadPackage(mySample, Nothing)
        Dim myConns As Connections = pkg.Connections
        
        ' Get the Properties collection from the connection manager.
        Dim myConnMgr As ConnectionManager = myConns(0)
        Dim connProperties As DtsProperties = myConnMgr.Properties
        
        ' View information about the RetainSameConnection property
        ' before setting it using the SetExpression method.
        Dim hasProperty As [Boolean] = connProperties.Contains("RetainSameConnection")
        Console.WriteLine("has RetainSameConnection? {0}", hasProperty)
        Dim myValue As [Object] = myConnMgr.Properties("RetainSameConnection").GetValue(myConnMgr)
        Dim mySValue As String = myValue.ToString()
        Console.WriteLine("value before is {0}", mySValue)
        Dim myTrueString As String = "true"
        
        ' Use SetExpression to set the value to true.
        myConnMgr.Properties("RetainSameConnection").SetExpression(myConnMgr, myTrueString)
        
        ' Validate the package to set the expression onto the property.
        Dim valResult As DTSExecResult = pkg.Validate(myConns, Nothing, Nothing, Nothing)
        
        ' Now that the value has been set, retrieve it.
        myValue = myConnMgr.Properties("RetainSameConnection").GetValue(myConnMgr)
        mySValue = myValue.ToString()
        Console.WriteLine("value after is {0}", mySValue)
        End Sub
    End Class
End Namespace

Sample Output:

has RetainSameConnection? True

value before is False

value after is 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 설치를 위한 하드웨어 및 소프트웨어 요구 사항을 참조하십시오.

참고 항목

참조

DtsProperty Class
DtsProperty Members
Microsoft.SqlServer.Dts.Runtime Namespace