SqlConnectionStringBuilder.Item[String] 속성

정의

지정된 키에 연결된 값을 가져오거나 설정합니다. C#에서는 이 속성이 인덱서입니다.

public:
 virtual property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ keyword); void set(System::String ^ keyword, System::Object ^ value); };
public override object this[string keyword] { get; set; }
member this.Item(string) : obj with get, set
Default Public Overrides Property Item(keyword As String) As Object

매개 변수

keyword
String

가져오거나 설정할 항목의 키입니다.

속성 값

지정한 키와 연결된 값입니다.

예외

keyword이 null 참조(Visual Basic의 경우 Nothing)인 경우

사용 가능한 키가 아닌 키를 추가하려고 한 경우

연결 문자열에 잘못된 값이 포함된 경우(예: 부울 값이나 숫자 값이 필요하지만 제공되지 않은 경우)

예제

다음 콘솔 애플리케이션 코드에서는 새 SqlConnectionStringBuilder를 만들고 Item[] 속성을 사용하여 키/값 쌍을 연결 문자열에 추가합니다.

class Program
{
    static void Main()
    {
        SqlConnectionStringBuilder builder =
            new SqlConnectionStringBuilder();
        builder["Data Source"] = "(local)";
        builder["Integrated Security"] = true;
        builder["Initial Catalog"] = "AdventureWorks";

        // Overwrite the existing value for the Data Source value.
        builder["Data Source"] = ".";

        Console.WriteLine(builder.ConnectionString);
        Console.WriteLine();
        Console.WriteLine("Press Enter to continue.");
        Console.ReadLine();
    }
}
Module Module1
    Sub Main()
        Dim builder As New SqlConnectionStringBuilder
        builder.Item("Data Source") = "(local)"
        ' Item is the default property, so 
        ' you needn't include it in the reference.
        builder("Integrated Security") = True
        builder.Item("Initial Catalog") = "AdventureWorks"

        ' Overwrite the existing value for the Data Source value.
        builder.Item("Data Source") = "."

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

설명

SqlConnectionStringBuilder에는 고정 크기의 사전이 포함되어 있기 때문에 사전에 없는 키를 추가하려고 하면 KeyNotFoundException이 throw됩니다.

적용 대상

추가 정보