OdbcConnectionStringBuilder.Item[String] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定與指定之索引鍵相關聯的值。 在 C# 中,這個屬性是索引子 (Indexer)。
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
)。
範例
主控台應用程式中的下列程式碼會建立新的 OdbcConnectionStringBuilder,並使用 Item[] 屬性將索引鍵/值組加入其連接字串。
using System.Data.Odbc;
class Program
{
static void Main()
{
OdbcConnectionStringBuilder builder =
new OdbcConnectionStringBuilder();
// Set up a connection string for a text file.
builder["Driver"] = "Microsoft Text Driver (*.txt; *.csv)";
builder["dbq"] = "C:\\TextFilesFolder";
builder["Extension"] = "asc,csv,tab,txt";
// Overwrite the existing value for the dbq value,
// because it already exists within the collection.
builder["dbq"] = "D:\\";
Console.WriteLine(builder.ConnectionString);
Console.WriteLine();
Console.WriteLine("Press Enter to continue.");
Console.ReadLine();
}
}
Imports System.Data.Odbc
Module Module1
Sub Main()
Dim builder As New OdbcConnectionStringBuilder
' Set up a connection string for a text file.
builder.Item("Driver") = "Microsoft Text Driver (*.txt; *.csv)"
' Note that Item is the default property, so
' you need not include it in the reference.
builder("dbq") = "C:\TextFilesFolder"
builder.Item("Extension") = "asc,csv,tab,txt"
' Overwrite the existing value for the dbq value,
' because it already exists within the collection.
builder.Item("dbq") = "D:\"
Console.WriteLine(builder.ConnectionString)
Console.WriteLine()
Console.WriteLine("Press Enter to continue.")
Console.ReadLine()
End Sub
End Module
備註
當您設定這個屬性時,如果指定的索引鍵已存在於字典中,則會取代值;否則會建立新的專案。