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

适用于

另请参阅