ConnectionStringSettingsCollection.RemoveAt(Int32) ConnectionStringSettingsCollection.RemoveAt(Int32) ConnectionStringSettingsCollection.RemoveAt(Int32) ConnectionStringSettingsCollection.RemoveAt(Int32) Method

Definition

Entfernt das ConnectionStringSettings-Objekt am angegebenen Index der Auflistung.Removes the ConnectionStringSettings object at the specified index in the collection.

public:
 void RemoveAt(int index);
public void RemoveAt (int index);
member this.RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)

Parameter

index
Int32 Int32 Int32 Int32

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

Beispiele

Das folgende Beispiel zeigt die Vorgehensweise beim Entfernen der ConnectionStringSettings Objekt am angegebenen Index in der Auflistung.The following example shows how to remove the ConnectionStringSettings object at the specified index in the collection.

static void RemoveConnectionStrings3()
{

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

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

        // Remove the element.
        csCollection.RemoveAt(0);

        // Save the configuration file.
        config.Save(ConfigurationSaveMode.Modified);
        
        Console.WriteLine(
             "Connection string settings removed.");
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}
Shared Sub RemoveConnectionStrings3() 
    
    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
        
        ' Remove the element.
        csCollection.RemoveAt(0)
        
        ' Save the configuration file.
        config.Save(ConfigurationSaveMode.Modified)
        
        Console.WriteLine( _
        "Connection string settings removed.")

    Catch err As ConfigurationErrorsException
        Console.WriteLine(err.ToString())
    End Try

End Sub 'RemoveConnectionStrings3

Gilt für:

Siehe auch