DbConnectionStringBuilder.Item[String] Proprietà

Definizione

Ottiene o imposta il valore associato alla chiave specificata.

public:
 virtual property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ keyword); void set(System::String ^ keyword, System::Object ^ value); };
public virtual object this[string keyword] { get; set; }
[System.ComponentModel.Browsable(false)]
public virtual object this[string keyword] { get; set; }
member this.Item(string) : obj with get, set
[<System.ComponentModel.Browsable(false)>]
member this.Item(string) : obj with get, set
Default Public Overridable Property Item(keyword As String) As Object

Parametri

keyword
String

Chiave dell'elemento da ottenere o impostare.

Valore della proprietà

Object

Valore associato alla chiave specificata. Se la chiave specificata non viene trovata, per ottenerla viene restituito un riferimento Null (Nothing in Visual Basic) e provando a impostarla viene creato un nuovo elemento con la chiave specificata.

Il passaggio di una chiave Nulle (Nothing in Visual Basic) genera un'ArgumentNullException. L'assegnazione di un valore Null rimuove la coppia chiave/valore.

Attributi

Eccezioni

keyword è un riferimento null (Nothing in Visual Basic).

La proprietà è stata impostata e l'interfaccia DbConnectionStringBuilder è in sola lettura.

-oppure-

La proprietà è impostata, keyword non esiste nella raccolta e DbConnectionStringBuilder è di dimensioni fisse.

Esempio

L'applicazione console seguente crea una nuova DbConnectionStringBuilder coppia chiave/valore e aggiunge le coppie chiave/valore alla stringa di connessione usando la Item[] proprietà .

static void Main()
{
    DbConnectionStringBuilder builder = new
        DbConnectionStringBuilder();
    builder["Data Source"] = "(local)";

    // Note that Item is the indexer, so
    // you do not include it in the reference.
    builder["integrated security"] = true;
    builder["Initial Catalog"] = "AdventureWorks";

    // Overwrite the existing value for the Data Source key,
    // because it already exists within the collection.
    builder["Data Source"] = ".";

    Console.WriteLine(builder.ConnectionString);
    Console.WriteLine();
    Console.WriteLine("Press Enter to continue.");
    Console.ReadLine();
}
Module Module1

    Sub Main()
        Dim builder As New DbConnectionStringBuilder
        builder.Item("Data Source") = "(local)"

        ' Item is the default property, so 
        ' you need not include it in the reference.
        builder("integrated security") = True
        builder.Item("Initial Catalog") = "AdventureWorks"

        ' Overwrite the existing value for the data source value, 
        ' because it already exists within the collection.
        builder.Item("Data Source") = "."

        Console.WriteLine(builder.ConnectionString)
        Console.WriteLine()
        Console.WriteLine("Press Enter to continue.")
        Console.ReadLine()
    End Sub

Commenti

Quando si imposta questa proprietà, se la chiave specificata esiste già nel dizionario, il valore viene sostituito; in caso contrario, viene creato un nuovo elemento.

Si applica a

Vedi anche