Redigera

Dela via


OdbcParameterCollection.Item[] Property

Definition

Gets or sets the OdbcParameter with a specified attribute.

Overloads

Item[String]

Gets or sets the OdbcParameter with the specified name.

Item[Int32]

Gets or sets the OdbcParameter at the specified index.

Item[String]

Source:
OdbcParameterCollection.cs
Source:
OdbcParameterCollection.cs
Source:
OdbcParameterCollection.cs
Source:
OdbcParameterCollection.cs
Source:
OdbcParameterCollection.cs

Gets or sets the OdbcParameter with the specified name.

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

Parameters

parameterName
String

The name of the parameter to retrieve.

Property Value

The OdbcParameter with the specified name.

Attributes

Exceptions

The name specified does not exist.

Examples

The following example searches for an OdbcParameter with a given ParameterName within an OdbcParameterCollection. 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 OdbcParameterCollection has already been created.

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

See also

Applies to

Item[Int32]

Source:
OdbcParameterCollection.cs
Source:
OdbcParameterCollection.cs
Source:
OdbcParameterCollection.cs
Source:
OdbcParameterCollection.cs
Source:
OdbcParameterCollection.cs

Gets or sets the OdbcParameter at the specified index.

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

Parameters

index
Int32

The zero-based index of the parameter to retrieve.

Property Value

The OdbcParameter at the specified index.

Attributes

Exceptions

The index specified does not exist.

Examples

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

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

See also

Applies to