Obtention d'informations sur le champ d'abonnement

La classe Subscription fournit les méthodes GetFieldName et GetFieldOrdinal pour accéder aux informations sur le champ d'abonnement.

La méthode GetFieldName retourne le nom d'un champ en fournissant son numéro ordinal. La méthode GetFieldOrdinal retourne l'ordinal d'un champ en fournissant son nom.

Les exemples ci-dessous montrent comment obtenir des informations sur le champ d'abonnement en utilisant le code managé et Microsoft Visual Basic Scripting Edition (VBScript) via COM Interop.

Exemple de code managé

L'exemple suivant illustre l'utilisation d'un objet Subscription dans le code managé pour retourner des informations sur le nom du champ d'abonnement.

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));

Exemple COM Interop

L'exemple VBScript suivant illustre l'utilisation d'un objet Subscription dans le code non managé pour retourner des informations sur le nom du champ d'abonnement :

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 

Voir aussi

Concepts

Création d'un objet d'abonnement
Ajout d'un abonnement
Mise à jour d'un abonnement
Suppression d'un abonnement
Remplissage d'une liste de paramètres régionaux d'abonnés
Remplissage d'une liste de fuseau horaire

Autres ressources

Vue NS<SubscriptionClassName>

Aide et Informations

Assistance sur SQL Server 2005