ConnectionManager.SetExpression(String, String) Metode

Definisi

Menetapkan ekspresi yang ditentukan ke properti . Tentukan null untuk menghapus ekspresi yang ada dari properti .

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)

Parameter

propertyName
String

Nama properti yang akan ditetapkan ekspresinya.

expression
String

Ekspresi .

Penerapan

Contoh

Contoh kode berikut menunjukkan cara menggunakan ekspresi untuk mengatur nilai properti yang khusus untuk manajer koneksi. Properti yang unik untuk pengelola koneksi terkandung dalam Properties koleksi.

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\100\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 System  
Imports System.Collections.Generic  
Imports System.Text  
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\100\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  

Contoh Output:

memiliki RetainSameConnection? True

nilai sebelumnya adalah False

nilai setelah adalah True

Keterangan

propertyName untuk objek pengelola koneksi dapat berupa string koneksi, deskripsi, nama, atau tingkat perlindungan. Untuk pengelola koneksi, saat ini adalah satu-satunya properti yang mendukung ekspresi. Selain properti pengelola koneksi umum ini, setiap jenis koneksi memiliki properti yang unik. Properti ini dicantumkan oleh Properties koleksi. Anda dapat menggunakan SetExpression metode untuk memberikan nama properti untuk diatur sebagai String parameter. Jika Anda ingin mengatur properti yang unik untuk koneksi dengan menggunakan Properties koleksi, mungkin berguna untuk mengetahui bahwa koleksi properti ini mewarisi dari DtsProperty. Perhatikan bahwa yang SetExpression diwariskan dari DtsProperty mengambil Object sebagai parameter pertama, bukan String.

Berlaku untuk