Jaa


Getting Subscription Field Information

The Subscription class provides the GetFieldName and GetFieldOrdinal methods to give access to subscription field information.

The GetFieldName method returns the name of a field by providing its ordinal number. The GetFieldOrdinal method of returns the ordinal of a field by providing its name.

The examples below show how to get subscription field information using managed code and using Microsoft Visual Basic Scripting Edition (VBScript) to illustrate COM interop.

Managed Code Example

The example shows how to use a Subscription object in managed code to return subscription field name information.

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 Example

The following VBScript example shows how to use a Subscription object in unmanaged code to return subscription field name information:

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 

See Also

Concepts

Creating a Subscription Object
Adding a Subscription
Updating a Subscription
Deleting a Subscription
Populating a Subscriber Locale List
Populating a Time Zone List

Other Resources

NS<SubscriptionClassName>View

Help and Information

Getting SQL Server 2005 Assistance