Bagikan melalui


ConnectionStringSettingsCollection.Item[] Properti

Definisi

Mendapatkan atau mengatur ConnectionStringSettings objek dalam koleksi.

Overload

Item[Int32]

Mendapatkan atau mengatur string koneksi pada indeks yang ditentukan dalam koleksi.

Item[String]

Mendapatkan atau mengatur ConnectionStringSettings objek dengan nama yang ditentukan dalam koleksi.

Item[Int32]

Sumber:
ConnectionStringSettingsCollection.cs
Sumber:
ConnectionStringSettingsCollection.cs
Sumber:
ConnectionStringSettingsCollection.cs

Mendapatkan atau mengatur string koneksi pada indeks yang ditentukan dalam koleksi.

public:
 property System::Configuration::ConnectionStringSettings ^ default[int] { System::Configuration::ConnectionStringSettings ^ get(int index); void set(int index, System::Configuration::ConnectionStringSettings ^ value); };
public System.Configuration.ConnectionStringSettings this[int index] { get; set; }
member this.Item(int) : System.Configuration.ConnectionStringSettings with get, set
Default Public Property Item(index As Integer) As ConnectionStringSettings

Parameter

index
Int32

Indeks ConnectionStringSettings objek dalam koleksi.

Nilai Properti

Objek ConnectionStringSettings pada indeks yang ditentukan.

Contoh

Contoh berikut menunjukkan cara mengakses ConnectionStringSettings objek pada indeks tertentu dalam ConnectionStringSettingsCollection koleksi.

static void GetItems()
{

    try
    {
        System.Configuration.Configuration config =
         ConfigurationManager.OpenExeConfiguration(
         ConfigurationUserLevel.None);

        // Clear the connection strings collection.
        ConnectionStringsSection csSection =
            config.ConnectionStrings;
        ConnectionStringSettingsCollection csCollection =
         csSection.ConnectionStrings;

        // Get the connection string setting element
        // with the specified index.
        ConnectionStringSettings cs =
            csCollection[0];

        Console.WriteLine(
             "cs: {0}", cs.Name);
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}
Shared Sub GetItems() 
    
    Try
        ' Get the application configuration file.
        Dim config _
        As System.Configuration.Configuration = _
        ConfigurationManager.OpenExeConfiguration( _
        ConfigurationUserLevel.None)

        ' Clear the connection strings collection.
        Dim csSection _
        As ConnectionStringsSection = _
        config.ConnectionStrings
        Dim csCollection _
        As ConnectionStringSettingsCollection = _
        csSection.ConnectionStrings
        
        ' Get the connection string setting element
        ' with the specified index.
        Dim cs _
        As ConnectionStringSettings = _
        csCollection(0)
        
        Console.WriteLine("cs: {0}", cs.Name)
    
    Catch err As ConfigurationErrorsException
        Console.WriteLine(err.ToString())
    End Try

End Sub

Keterangan

Di C#, properti ini adalah pengindeks ConnectionStringSettingsCollection untuk kelas .

Lihat juga

Berlaku untuk

Item[String]

Sumber:
ConnectionStringSettingsCollection.cs
Sumber:
ConnectionStringSettingsCollection.cs
Sumber:
ConnectionStringSettingsCollection.cs

Mendapatkan atau mengatur ConnectionStringSettings objek dengan nama yang ditentukan dalam koleksi.

public:
 property System::Configuration::ConnectionStringSettings ^ default[System::String ^] { System::Configuration::ConnectionStringSettings ^ get(System::String ^ name); };
public System.Configuration.ConnectionStringSettings this[string name] { get; }
member this.Item(string) : System.Configuration.ConnectionStringSettings
Default Public ReadOnly Property Item(name As String) As ConnectionStringSettings

Parameter

name
String

Nama ConnectionStringSettings objek dalam koleksi.

Nilai Properti

Objek ConnectionStringSettings dengan nama yang ditentukan; jika tidak, null.

Contoh

Contoh berikut menunjukkan cara mengakses objek bernama ConnectionStringSettings dalam ConnectionStringSettingsCollection koleksi.

static void GetItems2()
{

    try
    {
        System.Configuration.Configuration config =
         ConfigurationManager.OpenExeConfiguration(
         ConfigurationUserLevel.None);

        // Clear the connection strings collection.
        ConnectionStringsSection csSection =
            config.ConnectionStrings;
        ConnectionStringSettingsCollection csCollection =
         csSection.ConnectionStrings;

        // Get the connection string setting element
        // with the specified name.
        ConnectionStringSettings cs =
            csCollection["ConnStr0"];
       
        Console.WriteLine(
            "cs: {0}", cs.Name);
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine(err.ToString());
    }
}
Shared Sub GetItems2() 
    
    Try
        ' Get the application configuration file.
        Dim config _
        As System.Configuration.Configuration = _
        ConfigurationManager.OpenExeConfiguration( _
        ConfigurationUserLevel.None)

        ' Clear the connection strings collection.
        Dim csSection _
        As ConnectionStringsSection = _
        config.ConnectionStrings
        Dim csCollection _
        As ConnectionStringSettingsCollection = _
        csSection.ConnectionStrings
        
        ' Get the connection string setting element
        ' with the specified name.
        Dim cs _
        As ConnectionStringSettings = _
        csCollection("ConnStr0")
        
        Console.WriteLine("cs: {0}", cs.Name)
    
    Catch err As ConfigurationErrorsException
        Console.WriteLine(err.ToString())
    End Try

End Sub

Keterangan

Di C#, properti ini adalah pengindeks ConnectionStringSettingsCollection untuk kelas .

Lihat juga

Berlaku untuk