OleDbConnectionStringBuilder.Clear 메서드

정의

OleDbConnectionStringBuilder 인스턴스의 콘텐츠를 지웁니다.

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

예제

다음 예제에서는 호출한 데 따른 효과 Clear 메서드. 이 예제에서는 OleDbConnectionStringBuilder를 특정 키/값 쌍으로 채운 다음 Clear 메서드를 호출하고 결과를 표시합니다.

참고

이 예제에는 OleDbConnectionStringBuilder가 연결 문자열로 작업하는 방법을 보여 주기 위한 암호가 포함되어 있습니다. 애플리케이션에서는 Windows 인증을 사용하는 것이 좋습니다. 암호를 사용해야 하는 경우에는 애플리케이션에 하드 코드된 암호를 포함하지 마십시오.

using System.Data.OleDb;

class Program
{
    static void Main()
    {
        OleDbConnectionStringBuilder builder =
            new OleDbConnectionStringBuilder();
        builder.ConnectionString = @"Data Source=c:\Sample.mdb";

        // Call the Add method to explicitly add key/value
        // pairs to the internal collection.
        builder.Add("Provider", "Microsoft.Jet.Oledb.4.0");
        builder.Add("Jet OLEDB:Database Password", "MyPassword!");
        builder.Add("Jet OLEDB:System Database", @"C:\Workgroup.mdb");

        // set up row-level locking.
        builder.Add("Jet OLEDB:Database Locking Mode", 1);

        // Dump the contents of the "filled-in"
        // OleDbConnectionStringBuilder
        // to the console window.
        DumpBuilderContents(builder);

        // Clear current values and reset known keys to their
        // default values.
        builder.Clear();

        // Dump the contents of the newly emptied
        // OleDbConnectionStringBuilder
        // to the console window.
        DumpBuilderContents(builder);

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

    private static void DumpBuilderContents(OleDbConnectionStringBuilder builder)
    {
        Console.WriteLine("=================");
        Console.WriteLine("builder.ConnectionString = " + builder.ConnectionString);
        foreach (string key in builder.Keys)
        {
            Console.WriteLine(key + "=" + builder[key].ToString());
        }
    }
}
Imports System.Data.OleDb    

Module Module1
  Sub Main()
    Dim builder As New OleDbConnectionStringBuilder()
    builder.ConnectionString = "Data Source=C:\Sample.mdb"

    ' Call the Add method to explicitly add key/value
    ' pairs to the internal collection.
    builder.Add("Provider", "Microsoft.Jet.Oledb.4.0")
    builder.Add("Jet OLEDB:Database Password", "MyPassword!")
    builder.Add("Jet OLEDB:System Database", "C:\Workgroup.mdb")

    ' Set up row-level locking.
    builder.Add("Jet OLEDB:Database Locking Mode", 1)

    ' Dump the contents of the "filled-in" OleDbConnectionStringBuilder
    ' to the console window.
    DumpBuilderContents(builder)

    ' Clear current values and reset known keywords to their
    ' default values.
    builder.Clear()

    ' Dump the contents of the newly emptied 
    ' OleDbConnectionStringBuilder
    ' to the console window.
    DumpBuilderContents(builder)

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

  Private Sub DumpBuilderContents(ByVal builder As OleDbConnectionStringBuilder)
    Console.WriteLine("=================")
    Console.WriteLine("builder.ConnectionString = " & builder.ConnectionString)
    For Each key As String In builder.Keys
      Console.WriteLine(key & "=" & builder.Item(key).ToString)
    Next
  End Sub
End Module

설명

합니다 Clear 에서 모든 키/값 쌍을 제거 하는 메서드는 OleDbConnectionStringBuilder, 모든 해당 속성을 기본값으로 다시 설정 합니다. 여기에는 Count 속성을 0으로 설정하고 ConnectionString 속성을 빈 문자열로 설정하는 작업이 포함됩니다.

적용 대상

추가 정보