DtsEventHandlers.Contains(Object) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指出是否可以使用名稱、索引或識別碼當做索引來存取集合中的項目。
public:
bool Contains(System::Object ^ index);
public bool Contains (object index);
member this.Contains : obj -> bool
Public Function Contains (index As Object) As Boolean
參數
- index
- Object
要在集合中尋找之物件的名稱、索引或識別碼。
傳回
布林值,指出是否可以使用名稱、索引或識別碼來存取集合。 值為 true 時,表示可以使用語法 DtsEventHandlers [index] 來存取集合。 值為 false 時,表示無法使用索引來從集合中取出專案 DtsEventHandlers 。
範例
下列程式碼範例會抓取 DtsEventHandlers 集合,然後使用 Contains 來查看是否 [x] 可以在集合上使用專案語法。
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
namespace Microsoft.SqlServer.SSIS.Samples
{
class Program
{
static void Main(string[] args)
{
Package pkg = new Package();
// Set up a DtsEventHandler for the OnError event of the package.
DtsEventHandler dtsEHOE = (DtsEventHandler)pkg.EventHandlers.Add("OnError");
DtsEventHandler dtsEHW = (DtsEventHandler)pkg.EventHandlers.Add("OnWarning");
// Create the DtsEventHandlers collection.
DtsEventHandlers dtsEHColls = pkg.EventHandlers;
// Use the Contains method to see if the item[x] syntax can be used.
Boolean dtsContains = dtsEHColls.Contains(0);
Console.WriteLine("Item syntax can be used? {0}", dtsContains);
//Using the Item method syntax of [x], obtain the first entry and a name.
DtsEventHandler dtsEHFirstEntry = dtsEHColls[0];
String nameOfFirstItem = dtsEHColls[0].Name;
//Print the name of the log provider object located at position [0].
Console.WriteLine("The ID of the first event handler is: {0}", dtsEHFirstEntry.ID);
Console.WriteLine("The Name of the first event handler is: {0}", nameOfFirstItem);
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Namespace Microsoft.SqlServer.SSIS.Samples
Class Program
Shared Sub Main(ByVal args() As String)
Dim pkg As Package = New Package()
' Set up a DtsEventHandler for the OnError event of the package.
Dim dtsEHOE As DtsEventHandler = CType(pkg.EventHandlers.Add("OnError"), DtsEventHandler)
Dim dtsEHW As DtsEventHandler = CType(pkg.EventHandlers.Add("OnWarning"), DtsEventHandler)
' Create the DtsEventHandlers collection.
Dim dtsEHColls As DtsEventHandlers = pkg.EventHandlers
' Use the Contains method to see if the item[x] syntax can be used.
Dim dtsContains As Boolean = dtsEHColls.Contains(0)
Console.WriteLine("Item syntax can be used? {0}", dtsContains)
'Using the Item method syntax of [x], obtain the first entry and a name.
Dim dtsEHFirstEnTry As DtsEventHandler = dtsEHColls(0)
Dim nameOfFirstItem As String = dtsEHColls(0).Name
'Print the name of the log provider object located at position [0].
Console.WriteLine("The ID of the first event handler is: {0}", dtsEHFirstEnTry.ID)
Console.WriteLine("The Name of the first event handler is: {0}", nameOfFirstItem)
End Sub
End Class
End Namespace
範例輸出:
可以使用專案語法嗎? True
第一個事件處理常式的識別碼為: {4B9E438E-BA17-4A51-8235-3072AFF92F99}
第一個事件處理常式的名稱為: OnError