取得訂閱欄位資訊
Subscription 類別提供 GetFieldName 和 GetFieldOrdinal 方法,用來存取訂閱欄位資訊。
GetFieldName 方法會提供欄位的序號來傳回欄位名稱。GetFieldOrdinal 方法會提供欄位名稱來傳回欄位的序號。
下列範例顯示如何利用 Managed 程式碼來取得訂閱欄位資訊,利用 Microsoft Visual Basic Scripting Edition (VBScript) 來說明 COM Interop。
Managed 程式碼範例
這個範例顯示如何在 Managed 程式碼中,利用 Subscription 物件來傳回訂閱欄位名稱資訊。
string instanceName = "Tutorial";
string applicationName= "Weather";
string subscriptionClassName= "WeatherCity";
string fieldName = "City";
int ordinal = 2;
// Create the NSInstance object.
NSInstance testInstance = new NSInstance(instanceName);
// Create the NSApplication object.
NSApplication testApplication =
new NSApplication(testInstance, applicationName);
// Create the Subscription object.
Subscription testSubscription =
new Subscription(testApplication, subscriptionClassName);
// Use the GetFieldName method to return a field name
Console.WriteLine("Name of field " + ordinal.ToString() + ": " +
testSubscription.GetFieldName(ordinal));
// Use the GetFieldOrdinal to return a field ordinal
Console.WriteLine("Ordinal for the " + fieldName + " field: " +
testSubscription.GetFieldOrdinal(fieldName));
COM Interop 範例
下列 VBScript 範例顯示如何在 Unmanaged 程式碼中,利用 Subscription 物件來傳回訂閱欄位名稱資訊:
Dim testInstance, testApplication, testSubscription, _
ordinal, fieldName
const instanceName = "Tutorial"
const applicationName = "Weather"
const subscriptionClassName = "WeatherCity"
ordinal = 2
' Create the NSInstance object.
set testInstance = WScript.CreateObject( _
"Microsoft.SqlServer.NotificationServices.NSInstance")
testInstance.Initialize instanceName
' Create the NSApplication object.
set testApplication = WScript.CreateObject( _
"Microsoft.SqlServer.NotificationServices.NSApplication")
testApplication.Initialize (testInstance), applicationName
' Create the Subscription object.
set testSubscription = WScript.CreateObject( _
"Microsoft.SqlServer.NotificationServices.Subscription")
testSubscription.Initialize (testApplication), subscriptionClassName
' Get the name for a field identified by ordinal.
fieldName = testSubscription.GetFieldName(ordinal)
WScript.Echo "Field Name: ", fieldName
' Get the field ordinal for the field.
fieldName = testSubscription.GetFieldOrdinal(fieldName)
WScript.Echo "Field Ordinal: ", fieldName
請參閱
概念
建立訂閱物件
新增訂閱
更新訂閱
刪除訂閱
擴展訂閱者地區設定程式碼
擴展時區清單