Share via


Recupero di informazioni sul campo sottoscrizione

La classe Subscription include i metodi GetFieldName e GetFieldOrdinal per consentire l'accesso alle informazioni sul campo sottoscrizione.

Il metodo GetFieldName restituisce il nome di un campo fornendone il numero ordinale. Il metodo GetFieldOrdinal restituisce l'ordinale di un campo fornendone il nome.

Negli esempi seguenti viene illustrato come ottenere informazioni sul campo sottoscrizione utilizzando codice gestito e Microsoft Visual Basic Scripting Edition (VBScript) per illustrare l'interoperatività COM.

Esempio di codice gestito

Nell'esempio seguente viene illustrato come utilizzare un oggetto Subscription nel codice gestito per restituire informazioni sul nome del campo sottoscrizione.

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

Esempio di interoperatività COM

Nell'esempio VBScript seguente viene illustrato come utilizzare un oggetto Subscription nel codice non gestito per restituire le informazioni sul nome del campo sottoscrizione.

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 

Vedere anche

Concetti

Creazione di un oggetto di sottoscrizione
Aggiunta di una sottoscrizione
Aggiornamento di una sottoscrizione
Eliminazione di una sottoscrizione
Popolamento di un elenco delle impostazioni internazionali dei sottoscrittori
Popolamento di elenco di fusi orari

Altre risorse

Vista NS<SubscriptionClassName>

Guida in linea e informazioni

Assistenza su SQL Server 2005