次の方法で共有


ConnectionStringSettingsCollection.Remove メソッド

定義

ConnectionStringSettings オブジェクトをコレクションから削除します。

オーバーロード

Remove(ConnectionStringSettings)

指定した ConnectionStringSettings オブジェクトをコレクションから削除します。

Remove(String)

指定した ConnectionStringSettings オブジェクトをコレクションから削除します。

Remove(ConnectionStringSettings)

ソース:
ConnectionStringSettingsCollection.cs
ソース:
ConnectionStringSettingsCollection.cs
ソース:
ConnectionStringSettingsCollection.cs

指定した ConnectionStringSettings オブジェクトをコレクションから削除します。

public:
 void Remove(System::Configuration::ConnectionStringSettings ^ settings);
public void Remove (System.Configuration.ConnectionStringSettings settings);
member this.Remove : System.Configuration.ConnectionStringSettings -> unit
Public Sub Remove (settings As ConnectionStringSettings)

パラメーター

settings
ConnectionStringSettings

コレクション内の ConnectionStringSettings オブジェクト。

次の例は、指定した ConnectionStringSettings オブジェクトをコレクションから削除する方法を示しています。

static void RemoveConnectionStrings()
{

    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"];

        // Remove it.
        if (cs != null)
        {
            // Remove the element.
            csCollection.Remove(cs);

            // Save the configuration file.
            config.Save(ConfigurationSaveMode.Modified);
            
            Console.WriteLine(
             "Connection string settings removed.");
        }
        else
            Console.WriteLine(
                "Connection string settings does not exist.");
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}
Shared Sub RemoveConnectionStrings() 
    
    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")
        
        ' Remove it.
        If Not (cs Is Nothing) Then
            ' Remove the element.
            csCollection.Remove(cs)
            
            ' Save the configuration file.
            config.Save(ConfigurationSaveMode.Modified)
            
            Console.WriteLine( _
            "Connection string settings removed.")
        Else
            Console.WriteLine( _
            "Connection string settings does not exist.")
        End If
    
    Catch err As ConfigurationErrorsException
        Console.WriteLine(err.ToString())
    End Try

End Sub

こちらもご覧ください

適用対象

Remove(String)

ソース:
ConnectionStringSettingsCollection.cs
ソース:
ConnectionStringSettingsCollection.cs
ソース:
ConnectionStringSettingsCollection.cs

指定した ConnectionStringSettings オブジェクトをコレクションから削除します。

public:
 void Remove(System::String ^ name);
public void Remove (string name);
member this.Remove : string -> unit
Public Sub Remove (name As String)

パラメーター

name
String

コレクション内の ConnectionStringSettings オブジェクトの名前。

次の例は、指定した名前のオブジェクトを ConnectionStringSettings コレクションから削除する方法を示しています。

static void RemoveConnectionStrings2()
{

    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.Remove("ConnStr0");

        // Save the configuration file.
        config.Save(ConfigurationSaveMode.Modified);

        Console.WriteLine(
             "Connection string settings removed.");
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}
Shared Sub RemoveConnectionStrings2() 
    
    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.Remove("ConnStr0")
        
        
        ' 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

こちらもご覧ください

適用対象