ConnectionStringSettingsCollection.Item[] Property

Definition

Ruft ein ConnectionStringSettings-Objekt in der Auflistung ab oder legt dieses fest.Gets or sets a ConnectionStringSettings object in the collection.

Overloads

Item[Int32]

Ruft das die Verbindungszeichenfolge am angegebenen Index in der Auflistung ab oder legt diese fest.Gets or sets the connection string at the specified index in the collection.

Item[String]

Ruft das ConnectionStringSettings-Objekt mit dem angegebenen Namen in der Auflistung ab oder legt dieses fest.Gets or sets the ConnectionStringSettings object with the specified name in the collection.

Item[Int32]

Ruft das die Verbindungszeichenfolge am angegebenen Index in der Auflistung ab oder legt diese fest.Gets or sets the connection string at the specified index in the collection.

public:
 property System::Configuration::ConnectionStringSettings ^ default[int] { System::Configuration::ConnectionStringSettings ^ get(int index); void set(int index, System::Configuration::ConnectionStringSettings ^ value); };
public System.Configuration.ConnectionStringSettings this[int index] { get; set; }
member this.Item(int) : System.Configuration.ConnectionStringSettings with get, set
Default Public Property Item(index As Integer) As ConnectionStringSettings

Parameters

index
Int32

Der Index eines ConnectionStringSettings-Objekts in der Auflistung.The index of a ConnectionStringSettings object in the collection.

Property Value

ConnectionStringSettings

Das ConnectionStringSettings-Objekt am angegebenen Index.The ConnectionStringSettings object at the specified index.

Examples

Im folgenden Beispiel wird gezeigt, wie Sie auf ein ConnectionStringSettings Objekt an einem angegebenen Index in einer ConnectionStringSettingsCollection Auflistung zugreifen.The following example shows how to access a ConnectionStringSettings object at a given index in a ConnectionStringSettingsCollection collection.

static void GetItems()
{

    try
    {
        System.Configuration.Configuration config =
         ConfigurationManager.OpenExeConfiguration(
         ConfigurationUserLevel.None);

        // Clear the connection strings collection.
        ConnectionStringsSection csSection =
            config.ConnectionStrings;
        ConnectionStringSettingsCollection csCollection =
         csSection.ConnectionStrings;

        // Get the connection string setting element
        // with the specified index.
        ConnectionStringSettings cs =
            csCollection[0];

        Console.WriteLine(
             "cs: {0}", cs.Name);
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}
Shared Sub GetItems() 
    
    Try
        ' Get the application configuration file.
        Dim config _
        As System.Configuration.Configuration = _
        ConfigurationManager.OpenExeConfiguration( _
        ConfigurationUserLevel.None)

        ' Clear the connection strings collection.
        Dim csSection _
        As ConnectionStringsSection = _
        config.ConnectionStrings
        Dim csCollection _
        As ConnectionStringSettingsCollection = _
        csSection.ConnectionStrings
        
        ' Get the connection string setting element
        ' with the specified index.
        Dim cs _
        As ConnectionStringSettings = _
        csCollection(0)
        
        Console.WriteLine("cs: {0}", cs.Name)
    
    Catch err As ConfigurationErrorsException
        Console.WriteLine(err.ToString())
    End Try

End Sub

Remarks

In C# entspricht diese Eigenschaft dem Indexer für die ConnectionStringSettingsCollection-Klasse.In C#, this property is the indexer for the ConnectionStringSettingsCollection class.

See also

Item[String]

Ruft das ConnectionStringSettings-Objekt mit dem angegebenen Namen in der Auflistung ab oder legt dieses fest.Gets or sets the ConnectionStringSettings object with the specified name in the collection.

public:
 property System::Configuration::ConnectionStringSettings ^ default[System::String ^] { System::Configuration::ConnectionStringSettings ^ get(System::String ^ name); };
public:
 property System::Configuration::ConnectionStringSettings ^ default[System::String ^] { System::Configuration::ConnectionStringSettings ^ get(System::String ^ Name); };
public System.Configuration.ConnectionStringSettings this[string name] { get; }
public System.Configuration.ConnectionStringSettings this[string Name] { get; }
member this.Item(string) : System.Configuration.ConnectionStringSettings
Default Public ReadOnly Property Item(name As String) As ConnectionStringSettings
Default Public ReadOnly Property Item(Name As String) As ConnectionStringSettings

Parameters

nameName
String

Der Name eines ConnectionStringSettings-Objekts in der Auflistung.The name of a ConnectionStringSettings object in the collection.

Property Value

ConnectionStringSettings

Das ConnectionStringSettings-Objekt mit dem angegebenen Namen, andernfalls null.The ConnectionStringSettings object with the specified name; otherwise, null.

Examples

Das folgende Beispiel zeigt, wie Sie auf ein benanntes ConnectionStringSettings Objekt in einer ConnectionStringSettingsCollection Auflistung zugreifen.The following example shows how to access a named ConnectionStringSettings object in a ConnectionStringSettingsCollection collection.

static void GetItems2()
{

    try
    {
        System.Configuration.Configuration config =
         ConfigurationManager.OpenExeConfiguration(
         ConfigurationUserLevel.None);

        // Clear the connection strings collection.
        ConnectionStringsSection csSection =
            config.ConnectionStrings;
        ConnectionStringSettingsCollection csCollection =
         csSection.ConnectionStrings;

        // Get the connection string setting element
        // with the specified name.
        ConnectionStringSettings cs =
            csCollection["ConnStr0"];
       
        Console.WriteLine(
            "cs: {0}", cs.Name);
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}
Shared Sub GetItems2() 
    
    Try
        ' Get the application configuration file.
        Dim config _
        As System.Configuration.Configuration = _
        ConfigurationManager.OpenExeConfiguration( _
        ConfigurationUserLevel.None)

        ' Clear the connection strings collection.
        Dim csSection _
        As ConnectionStringsSection = _
        config.ConnectionStrings
        Dim csCollection _
        As ConnectionStringSettingsCollection = _
        csSection.ConnectionStrings
        
        ' Get the connection string setting element
        ' with the specified name.
        Dim cs _
        As ConnectionStringSettings = _
        csCollection("ConnStr0")
        
        Console.WriteLine("cs: {0}", cs.Name)
    
    Catch err As ConfigurationErrorsException
        Console.WriteLine(err.ToString())
    End Try

End Sub

Remarks

In C# entspricht diese Eigenschaft dem Indexer für die ConnectionStringSettingsCollection-Klasse.In C#, this property is the indexer for the ConnectionStringSettingsCollection class.

See also

Applies to