Export (0) Print
Expand All

OleDbConnectionStringBuilder.Item Property

Note: This property is new in the .NET Framework version 2.0.

Gets or sets the value associated with the specified key. In C#, this property is the indexer.

Namespace: System.Data.OleDb
Assembly: System.Data (in system.data.dll)

public override Object this [
	string keyword
] { get; set; 
/** @property */
public Object get_Item (String keyword)

/** @property */
public void set_Item (String keyword, Object value)

JScript supports the use of indexed properties, but not the declaration of new ones.



The key of the item to get or set.

Property Value

The value associated with the specified key.

Exception typeCondition


The connection string is incorrectly formatted (perhaps missing the required "=" within a key/value pair).


keyword is a null reference (Nothing in Visual Basic).

Because setting the Provider property may add corresponding items to the collection of key/value pairs (depending on the behavior of the specific provider), you may be able to retrieve a value for a key you have not set explicitly. For example, as soon as you have set the Provider property to "sqloledb," you can retrieve the "Workstation ID" value even if you have not set it yourself. See the example in this topic for a demonstration.

The following example uses the Item property (the indexer, in C#) to retrieve and set values within the collection of key/value pairs. Note that setting the provider, in this case, also provides default values for all the key/value pairs associated with the selected provider.

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:Database Password"] = "DataPassword";
        builder["Jet OLEDB:Encrypt Database"] = true;
        builder["Jet OLEDB:System database"] = @"C:\Workgroup.mdw";


        // 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.");


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

© 2015 Microsoft