获取订阅字段信息
Subscription 类提供 GetFieldName 和 GetFieldOrdinal 方法以获取对订阅字段信息的访问。
向其提供字段的序号,GetFieldName 方法可返回字段的名称。向其提供字段的名称,GetFieldOrdinal 方法可返回字段的序号。
下面的示例说明如何使用托管代码获取订阅字段信息以及如何使用 Microsoft Visual Basic Scripting Edition (VBScript) 说明 COM interop。
托管代码示例
该示例说明如何在托管代码中使用 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 示例说明如何在非托管代码中使用 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
请参阅
概念
创建订阅对象
添加订阅
更新订阅
删除订阅
填充订阅服务器区域设置列表
填充时区列表