편집

다음을 통해 공유


OleDbParameterCollection.Item[] Property

Definition

Gets or sets the OleDbParameter with a specified attribute.

Overloads

Item[String]

Gets or sets the OleDbParameter with the specified name.

Item[Int32]

Gets or sets the OleDbParameter at the specified index.

Item[String]

Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs

Gets or sets the OleDbParameter with the specified name.

public:
 property System::Data::OleDb::OleDbParameter ^ default[System::String ^] { System::Data::OleDb::OleDbParameter ^ get(System::String ^ parameterName); void set(System::String ^ parameterName, System::Data::OleDb::OleDbParameter ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Data.OleDb.OleDbParameter this[string parameterName] { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.Item(string) : System.Data.OleDb.OleDbParameter with get, set
Default Public Property Item(parameterName As String) As OleDbParameter

Parameters

parameterName
String

The name of the parameter to retrieve.

Property Value

The OleDbParameter with the specified name.

Attributes

Exceptions

The name specified does not exist.

Examples

The following example searches for an OleDbParameter with a given ParameterName within an OleDbParameterCollection. If the parameter exists, the example displays the name and index of the parameter. If the parameter does not exist, the example displays an error. This example assumes that an OleDbParameterCollection has already been created.

public void SearchParameters()
{
    // ...
    // create OleDbParameterCollection parameters
    // ...
    if (!parameters.Contains("Description"))
        Console.WriteLine("ERROR: no such parameter in the collection");
    else
        Console.WriteLine("Name: " + parameters["Description"].ToString() +
            "Index: " + parameters.IndexOf("Description").ToString());
}
Public Sub SearchParameters()
    ' ...
    ' create OleDbParameterCollection parameters
    ' ...
    If Not parameters.Contains("Description") Then
        Console.WriteLine("ERROR: no such parameter in the collection")
    Else
        Console.WriteLine("Name: " & parameters("Description").ToString() & _
            "Index: " & parameters.IndexOf("Description").ToString())
    End If
End Sub

See also

Applies to

Item[Int32]

Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs
Source:
OleDbParameterCollection.cs

Gets or sets the OleDbParameter at the specified index.

public:
 property System::Data::OleDb::OleDbParameter ^ default[int] { System::Data::OleDb::OleDbParameter ^ get(int index); void set(int index, System::Data::OleDb::OleDbParameter ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Data.OleDb.OleDbParameter this[int index] { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.Item(int) : System.Data.OleDb.OleDbParameter with get, set
Default Public Property Item(index As Integer) As OleDbParameter

Parameters

index
Int32

The zero-based index of the parameter to retrieve.

Property Value

The OleDbParameter at the specified index.

Attributes

Exceptions

The index specified does not exist.

Examples

The following example creates an OleDbParameterCollection, adds instances of OleDbParameter to the collection, displays the names of its OleDbParameter objects, and then clears the collection.

public void CreateParamCollection(OleDbCommand command)
{
    OleDbParameterCollection paramCollection = command.Parameters;
    paramCollection.Add("@CategoryName", OleDbType.Char);
    paramCollection.Add("@Description", OleDbType.Char);
    paramCollection.Add("@Picture", OleDbType.Binary);
    string parameterNames = "";
    for (int i=0; i < paramCollection.Count; i++)
        parameterNames += paramCollection[i].ToString() + "\n";
    Console.WriteLine(parameterNames);
    paramCollection.Clear();
}
Public Sub CreateParamCollection(command As OleDbCommand)
    Dim paramCollection As OleDbParameterCollection = _
        command.Parameters
    paramCollection.Add("@CategoryName", OleDbType.Char)
    paramCollection.Add("@Description", OleDbType.Char)
    paramCollection.Add("@Picture", OleDbType.Binary)
    Dim parameterNames As String = ""
    For i As Integer = 0 To paramCollection.Count - 1
        parameterNames += paramCollection(i).ToString() & _
            ControlChars.Cr
    Next
    Console.WriteLine(parameterNames)
    paramCollection.Clear()
End Sub

See also

Applies to