Bagikan melalui


DbConnectionStringBuilder.Remove(String) Metode

Definisi

Menghapus entri dengan kunci yang ditentukan dari DbConnectionStringBuilder instans.

public:
 virtual bool Remove(System::String ^ keyword);
public virtual bool Remove (string keyword);
abstract member Remove : string -> bool
override this.Remove : string -> bool
Public Overridable Function Remove (keyword As String) As Boolean

Parameter

keyword
String

Kunci pasangan kunci/nilai yang akan dihapus dari string koneksi dalam ini DbConnectionStringBuilder.

Mengembalikan

truejika kunci ada dalam string koneksi dan dihapus; false jika kunci tidak ada.

Pengecualian

keyword null (Nothing dalam Visual Basic)

DbConnectionStringBuilder bersifat baca-saja, atau DbConnectionStringBuilder memiliki ukuran tetap.

Contoh

static void Main()
{
    DbConnectionStringBuilder builder = new
        DbConnectionStringBuilder();
    builder.ConnectionString =
        @"Provider=Microsoft.Jet.OLEDB.4.0;Data
            Source=C:\Demo.mdb;" +
        "Jet OLEDB:System Database=system.mdw;";

    // Try to remove an existing item.
    TryRemove(builder, "Provider");

    // Try to remove a nonexistent item.
    TryRemove(builder, "User ID");

    // Try to remove an existing item,
    // demonstrating that the search isn't
    // case sensitive.
    TryRemove(builder, "DATA SOURCE");
    Console.ReadLine();
}

static void TryRemove(DbConnectionStringBuilder builder, string itemToRemove)
{
    if (builder.Remove(itemToRemove))
    {
        Console.WriteLine(@"Removed '{0}'", itemToRemove);
    }
    else
    {
        Console.WriteLine(@"Unable to remove '{0}'", itemToRemove);
    }
    Console.WriteLine(builder.ConnectionString);
}
Sub Main()
    Dim builder As New DbConnectionStringBuilder
    builder.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Demo.mdb;" & _
        "Jet OLEDB:System Database=system.mdw;"

    ' Try to remove an existing item.
    TryRemove(builder, "Provider")

    ' Try to remove a nonexistent item.
    TryRemove(builder, "User ID")

    ' Try to remove an existing item, 
    ' demonstrating that the search isn't 
    ' case sensitive.
    TryRemove(builder, "DATA SOURCE")
    Console.ReadLine()
End Sub

Sub TryRemove(ByVal builder As DbConnectionStringBuilder, _
    ByVal itemToRemove As String)

    If builder.Remove(itemToRemove) Then
        Console.WriteLine("Removed '{0}'", itemToRemove)
    Else
        Console.WriteLine("Unable to remove '{0}'", itemToRemove)
    End If
    Console.WriteLine(builder.ConnectionString)
End Sub

Sampel ini menampilkan output berikut:

Removed 'Provider'
data source=C:\Demo.mdb;jet oledb:system database=system.mdw
Unable to remove 'User ID'
data source=C:\Demo.mdb;jet oledb:system database=system.mdw
Removed 'DATA SOURCE'
jet oledb:system database=system.mdw

Keterangan

Remove Karena metode mengembalikan nilai yang menunjukkan keberhasilannya, tidak perlu mencari kunci sebelum mencoba menghapus pasangan kunci/nilai dari DbConnectionStringBuilder instans.

Berlaku untuk

Lihat juga