Поделиться через


ConnectionStringSettingsCollection.RemoveAt(Int32) Метод

Определение

Удаляет объект ConnectionStringSettings по указанному индексу в коллекции.

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

Параметры

index
Int32

Индекс объекта ConnectionStringSettings в коллекции.

Примеры

В следующем примере показано, как удалить ConnectionStringSettings объект по указанному индексу в коллекции.

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

Применяется к

См. также раздел