次の方法で共有


Contains メソッド

例外がスローされることなく、インデックスを使用してコレクション内の ConnectionManager 項目にアクセスできるかどうかを示す Boolean を返します。

名前空間:  Microsoft.SqlServer.Dts.Runtime
アセンブリ:  Microsoft.SqlServer.ManagedDTS (Microsoft.SqlServer.ManagedDTS.dll)

構文

'宣言
Public Function Contains ( _
    index As Object _
) As Boolean
'使用
Dim instance As Connections
Dim index As Object
Dim returnValue As Boolean

returnValue = instance.Contains(index)
public bool Contains(
    Object index
)
public:
bool Contains(
    Object^ index
)
member Contains : 
        index:Object -> bool 
public function Contains(
    index : Object
) : boolean

パラメーター

  • index
    型: System. . :: . .Object
    コレクション内で検索する名前、説明、ID、またはインデックスです。

戻り値

型: System. . :: . .Boolean
Connections[index] 構文を使用してコレクションにアクセスできる場合は true です。名前、説明、またはインデックスでコレクションにアクセスできる場合は true、インデックスを使用して Connections コレクションから項目を取得できない場合は false です。

使用例

次のコード サンプルでは、コレクションから、新しく追加した ADO.NET 接続マネージャーを削除します。その後、Contains メソッドを使用して、接続マネージャーが削除されたことを確認します。

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

namespace Connections_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\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx";

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

            // Show how many connections are in the package.
            int myConnsCount = myConns.Count;
            Console.WriteLine("The number of connections is: {0}", myConnsCount);

            // Add an OLEDB connection manager.
            ConnectionManager myConn = pkg.Connections.Add("OLEDB");
            myConn.Name = "My OLEDB ConnectionManager";
            myConn.ConnectionString = "Data Source=.;Initial Catalog=AdventureWorks2008R2;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Auto Translate=False;";

            // Verify the addition of one connection manager.
            myConnsCount = myConns.Count;
            Console.WriteLine("The number of connections now is: {0}", myConnsCount);

            // Write out the names of the connection managers.
            foreach (ConnectionManager myCMgrs in myConns)
            {
                Console.WriteLine("Name:        {0}", myCMgrs.Name);
                Console.WriteLine("ID:          {0}", myCMgrs.ID);
                Console.WriteLine("--------------------------------------------");
            }

            // Remove the connection manager by name.
            pkg.Connections.Remove("My OLEDB ConnectionManager");

            // Verify the removal of the connection manager.
            myConnsCount = myConns.Count;
            Console.WriteLine("The number of connections is finally: {0}", myConnsCount);

            // Using the Contains method, verify if the connection is in the collection.
            Boolean connRemoved = myConns.Contains("My OLEDB ConnectionManager");
            Console.WriteLine("The connection is still in the collection? {0}", connRemoved);
            Console.WriteLine();
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
 
Namespace Connections_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\ExecuteProcess Sample\ExecuteProcess\UsingExecuteProcess.dtsx" 
 
            ' Create an application and load the sample.
            Dim app As Application =  New Application() 
            Dim pkg As Package =  app.LoadPackage(mySample,Nothing) 
            Dim myConns As Connections =  pkg.Connections 
 
            ' Show how many connections are in the package.
            Dim myConnsCount As Integer =  myConns.Count 
            Console.WriteLine("The number of connections is: {0}", myConnsCount)
 
            ' Add an OLEDB connection manager.
            Dim myConn As ConnectionManager =  pkg.Connections.Add("OLEDB") 
            myConn.Name = "My OLEDB ConnectionManager"
            myConn.ConnectionString = "Data Source=.;Initial Catalog=AdventureWorks2008R2;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Auto Translate=False;"
 
            ' Verify the addition of one connection manager.
            myConnsCount = myConns.Count
            Console.WriteLine("The number of connections now is: {0}", myConnsCount)
 
            ' Write out the names of the connection managers.
            Dim myCMgrs As ConnectionManager
            For Each myCMgrs In myConns
                Console.WriteLine("Name:        {0}", myCMgrs.Name)
                Console.WriteLine("ID:          {0}", myCMgrs.ID)
                Console.WriteLine("--------------------------------------------")
            Next
 
            ' Remove the connection manager by name.
            pkg.Connections.Remove("My OLEDB ConnectionManager")
 
            ' Verify the removal of the connection manager.
            myConnsCount = myConns.Count
            Console.WriteLine("The number of connections is finally: {0}", myConnsCount)
 
            ' Using the Contains method, verify if the connection is in the collection.
            Dim connRemoved As Boolean =  myConns.Contains("My OLEDB ConnectionManager") 
            Console.WriteLine("The connection is still in the collection? {0}", connRemoved)
            Console.WriteLine()
        End Sub
    End Class
End Namespace

サンプルの出力 :

The number of connections is: 3

The number of connections now is: 4

Name: Create_Execute_Process_Dest.sql

ID: {B52C0D78-5402-4544-BFEC-2BE203900C91}

--------------------------------------------

Name: customers

ID: {4F945623-B43F-470F-9D1E-D2A0B09177AE}

--------------------------------------------

Name: localhost.AdventureWorks2008R2

ID: {47179DDF-BD08-4E29-87C4-3A3D77105C2B}

--------------------------------------------

Name: My OLEDB ConnectionManager

ID: {90DF568E-ECB1-46D2-8DCB-3E2C67391E64}

--------------------------------------------

The number of connections is finally: 3

The connection is still in the collection?False