Bagikan melalui


OdbcConnectionStringBuilder.Remove(String) Metode

Definisi

Menghapus entri dengan kunci yang ditentukan dari OdbcConnectionStringBuilder instans.

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

Parameter

keyword
String

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

Mengembalikan

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

Pengecualian

keyword null (Nothing dalam Visual Basic).

Contoh

Contoh berikut membuat instans OdbcConnectionStringBuilder dan menunjukkan perilaku Remove metode .

using System.Data.Odbc;

class Program
{
    static void Main()
    {
        OdbcConnectionStringBuilder builder =
            new OdbcConnectionStringBuilder();
        builder.ConnectionString =
            "Driver={SQL Server};Server=(local);" +
            "Database=AdventureWorks;Trusted_Connection=yes;";

        Console.WriteLine(builder.ConnectionString);

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

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

        // Try to remove an existing item,
        // demonstrating that the search is not
        // case sensitive.
        TryRemove(builder, "DATABASE");

        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }

    static void TryRemove(OdbcConnectionStringBuilder builder,
        string itemToRemove)
    {

        if (builder.Remove(itemToRemove))
        {
            Console.WriteLine("Removed '{0}'", itemToRemove);
        }
        else
        {
            Console.WriteLine("Unable to remove '{0}'", itemToRemove);
        }
        Console.WriteLine(builder.ConnectionString);
    }
}
Imports System.Data.Odbc  
  
Module Module1
  Sub Main()
    Dim builder As New OdbcConnectionStringBuilder
    builder.ConnectionString = _
     "Driver={SQL Server};Server=(local);" & _
     "Database=AdventureWorks;Trusted_Connection=yes;"

    Console.WriteLine(builder.ConnectionString)

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

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

    ' Try to remove an existing item, 
    ' demonstrating that the search is not 
    ' case sensitive.
    TryRemove(builder, "DATABASE")

    Console.WriteLine("Press Enter to continue.")
    Console.ReadLine()
  End Sub

  Sub TryRemove(ByVal builder As OdbcConnectionStringBuilder, _
      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
End Module

Keterangan

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

Berlaku untuk

Lihat juga