OleDbConnectionStringBuilder.Item[String] 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 키와 연결된 값을 가져오거나 설정합니다. 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 참조(Nothing Visual Basic의 경우)입니다.
예제
다음 예제에서는 속성(C#의 인덱서)을 사용하여 Item[] 키/값 쌍의 컬렉션 내에서 값을 검색하고 설정합니다. 이 경우 공급자를 설정하면 선택한 공급자와 연결된 모든 키/값 쌍에 대한 기본값도 제공됩니다.
using System.Data.OleDb;
class Program
{
static void Main()
{
OleDbConnectionStringBuilder builder = new OleDbConnectionStringBuilder();
builder.Provider = "Microsoft.Jet.Oledb.4.0";
builder.DataSource = @"C:\Sample.mdb";
// Set properties using the Item property (the indexer, in C#).
builder["Jet OLEDB:Encrypt Database"] = true;
builder["Jet OLEDB:System database"] = @"C:\Workgroup.mdw";
Console.WriteLine(builder.ConnectionString);
Console.WriteLine();
// Use the Item property to retrieve values as well.
Console.WriteLine(builder["Jet OLEDB:System database"]);
Console.WriteLine(builder["Jet OLEDB:Encrypt Database"]);
// You can set or retrieve any of the "default" values for the
// provider, even if you didn't set their values.
Console.WriteLine(builder["Jet OLEDB:Database Locking Mode"]);
Console.WriteLine(builder["Jet OLEDB:Global Partial Bulk Ops"]);
Console.WriteLine("Press Enter to continue.");
Console.ReadLine();
}
}
Imports System.Data.OleDb
Module Module1
Sub Main()
Dim builder As New OleDbConnectionStringBuilder
builder.Provider = "Microsoft.Jet.Oledb.4.0"
builder.DataSource = "C:\Sample.mdb"
' Set properties using the Item property.
builder.Item("Jet OLEDB:Encrypt Database") = True
' Because Item is the default property, you can leave out
' the explicit reference.
builder("Jet OLEDB:System database") = "C:\Workgroup.mdw"
Console.WriteLine(builder.ConnectionString)
Console.WriteLine()
' Use the Item property to retrieve values, as well.
Console.WriteLine(builder.Item("Jet OLEDB:System database"))
Console.WriteLine(builder("Jet OLEDB:Encrypt Database"))
' You can set or retrieve any of the "default" values for the
' provider, as well, even if you did not set their values. Again,
' explicitly specifying the Item property name is optional.
Console.WriteLine(builder.Item("Jet OLEDB:Database Locking Mode"))
Console.WriteLine(builder("Jet OLEDB:Global Partial Bulk Ops"))
Console.WriteLine("Press Enter to continue.")
Console.ReadLine()
End Sub
End Module
설명
속성을 설정하면 Provider 특정 공급자의 동작에 따라 키/값 쌍의 컬렉션에 해당 항목이 추가될 수 있으므로 명시적으로 설정하지 않은 키의 값을 검색할 수 있습니다. 예를 들어 속성을 "sqloledb"로 설정하는 즉시 직접 설정 Provider 하지 않은 경우에도 "워크스테이션 ID" 값을 검색할 수 있습니다. 데모는 이 항목의 예제를 참조하세요.