Bagikan melalui


SqlConnectionStringBuilder.Clear Metode

Definisi

Menghapus konten instans SqlConnectionStringBuilder .

public:
 override void Clear();
public override void Clear ();
override this.Clear : unit -> unit
Public Overrides Sub Clear ()

Contoh

Contoh berikut menunjukkan pemanggilan Clear metode . Contoh ini mengisi SqlConnectionStringBuilder dengan beberapa pasangan kunci/nilai, lalu memanggil Clear metode dan menunjukkan hasilnya.

using System.Data.SqlClient;

class Program
{
    static void Main()
    {
        SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
        builder.DataSource = "(local)";
        builder.IntegratedSecurity = true;
        builder.InitialCatalog = "AdventureWorks";
        Console.WriteLine("Initial connection string: " + builder.ConnectionString);

        builder.Clear();
        Console.WriteLine("After call to Clear, count = " + builder.Count);
        Console.WriteLine("Cleared connection string: " + builder.ConnectionString);
        Console.WriteLine();

        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }
}
Imports System.Data.SqlClient
    
Module Module1
    Sub Main()
        Dim builder As New SqlConnectionStringBuilder
        builder.DataSource = "(local)"
        builder.IntegratedSecurity = True
        builder.InitialCatalog = "AdventureWorks"
        Console.WriteLine("Initial connection string: " & builder.ConnectionString)

        builder.Clear()
        Console.WriteLine("After call to Clear, count = " & builder.Count)
        Console.WriteLine("Cleared connection string: " & builder.ConnectionString)
        Console.WriteLine()

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

Keterangan

Metode ini Clear menghapus semua pasangan kunci/nilai dari SqlConnectionStringBuilder, dan mengatur ulang semua properti yang sesuai. Ini termasuk mengatur properti ke Count 0, dan mengatur ConnectionString properti ke string kosong.

Berlaku untuk

Lihat juga