Export (0) Print
Expand All

OdbcParameterCollection Class

Represents a collection of parameters relevant to an OdbcCommand and their respective mappings to columns in a DataSet. This class cannot be inherited.

Namespace:  System.Data.Odbc
Assembly:  System.Data (in System.Data.dll)

[ListBindableAttribute(false)]
public sealed class OdbcParameterCollection : DbParameterCollection

The OdbcParameterCollection type exposes the following members.

  NameDescription
Public propertyCountReturns an Integer that contains the number of elements in the OdbcParameterCollection. Read-only. (Overrides DbParameterCollection.Count.)
Public propertyIsFixedSizeGets a value that indicates whether the OdbcParameterCollection has a fixed size. Read-only. (Overrides DbParameterCollection.IsFixedSize.)
Public propertyIsReadOnlyGets a value that indicates whether the OdbcParameterCollection is read-only. (Overrides DbParameterCollection.IsReadOnly.)
Public propertyIsSynchronizedGets a value that indicates whether the OdbcParameterCollection is synchronized. Read-only. (Overrides DbParameterCollection.IsSynchronized.)
Public propertyItem[Int32]Gets or sets the OdbcParameter at the specified index.
Public propertyItem[String]Gets or sets the OdbcParameter with the specified name.
Public propertySyncRootGets an object that can be used to synchronize access to the OdbcParameterCollection. Read-only. (Overrides DbParameterCollection.SyncRoot.)
Top

  NameDescription
Public methodAdd(Object)Adds the specified OdbcParameter object to the OdbcParameterCollection. (Overrides DbParameterCollection.Add(Object).)
Public methodAdd(OdbcParameter)Adds the specified OdbcParameter to the OdbcParameterCollection.
Public methodAdd(String, OdbcType)Adds an OdbcParameter to the OdbcParameterCollection, given the parameter name and data type.
Public methodAdd(String, Object) Obsolete. Adds an OdbcParameter to the OdbcParameterCollection given the parameter name and value.
Public methodAdd(String, OdbcType, Int32)Adds an OdbcParameter to the OdbcParameterCollection, given the parameter name, data type, and column length.
Public methodAdd(String, OdbcType, Int32, String)Adds an OdbcParameter to the OdbcParameterCollection given the parameter name, data type, column length, and source column name.
Public methodAddRange(Array)Adds an array of values to the end of the OdbcParameterCollection. (Overrides DbParameterCollection.AddRange(Array).)
Public methodAddRange(OdbcParameter[])Adds an array of OdbcParameter values to the end of the OdbcParameterCollection.
Public methodAddWithValueAdds a value to the end of the OdbcParameterCollection.
Public methodClearRemoves all OdbcParameter objects from the OdbcParameterCollection. (Overrides DbParameterCollection.Clear().)
Public methodContains(Object)Determines whether the specified Object is in this OdbcParameterCollection. (Overrides DbParameterCollection.Contains(Object).)
Public methodContains(OdbcParameter)Determines whether the specified OdbcParameter is in this OdbcParameterCollection.
Public methodContains(String)Gets a value indicating whether an OdbcParameter object with the specified parameter name exists in the collection. (Overrides DbParameterCollection.Contains(String).)
Public methodCopyTo(Array, Int32)Copies all the elements of the current OdbcParameterCollection to the specified one-dimensional Array starting at the specified destination Array index. (Overrides DbParameterCollection.CopyTo(Array, Int32).)
Public methodCopyTo(OdbcParameter[], Int32)Copies all the elements of the current OdbcParameterCollection to the specified OdbcParameterCollection starting at the specified destination index.
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetEnumeratorReturns an enumerator that iterates through the OdbcParameterCollection. (Overrides DbParameterCollection.GetEnumerator().)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIndexOf(Object)Gets the location of the specified Object within the collection. (Overrides DbParameterCollection.IndexOf(Object).)
Public methodIndexOf(OdbcParameter)Gets the location of the specified OdbcParameter within the collection.
Public methodIndexOf(String)Gets the location of the specified OdbcParameter with the specified name. (Overrides DbParameterCollection.IndexOf(String).)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodInsert(Int32, OdbcParameter)Inserts a OdbcParameter object into the OdbcParameterCollection at the specified index.
Public methodInsert(Int32, Object)Inserts a Object into the OdbcParameterCollection at the specified index. (Overrides DbParameterCollection.Insert(Int32, Object).)
Public methodRemove(Object)Removes the Object object from the OdbcParameterCollection. (Overrides DbParameterCollection.Remove(Object).)
Public methodRemove(OdbcParameter)Removes the OdbcParameter from the OdbcParameterCollection.
Public methodRemoveAt(Int32)Removes the OdbcParameter from the OdbcParameterCollection at the specified index. (Overrides DbParameterCollection.RemoveAt(Int32).)
Public methodRemoveAt(String)Removes the OdbcParameter from the OdbcParameterCollection with the specified parameter name. (Overrides DbParameterCollection.RemoveAt(String).)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate propertyIDataParameterCollection.ItemGets or sets the parameter at the specified index. (Inherited from DbParameterCollection.)
Explicit interface implemetationPrivate propertyIList.ItemGets or sets the element at the specified index. (Inherited from DbParameterCollection.)
Top

The number of parameters in the collection must equal the number of parameter placeholders within the command text, or else the .NET Framework Data Provider for ODBC raises an error.

The following example assumes that the data source has a table named MoneyTable and a stored procedure named MoneyProcedure, which are defined as follows:

CREATE TABLE MoneyTable (col1 int, col2 smallmoney, col3 decimal);

CREATE PROC MoneyProcedure (@p1 int, @p2 smallmoney, @p3 decimal) 
AS 
INSERT INTO MyTable VALUES (@p1, @p2, @p3);

The example creates parameters and calls the MoneyProcedure stored procedure.

public void CreateMyProc(OdbcConnection connection)
{
    OdbcCommand command = connection.CreateCommand();
    command.CommandText = "{ call MyProc(?,?,?) }";

    OdbcParameter param = new OdbcParameter();
    param.DbType = DbType.Int32;
    param.Value = 1;
    command.Parameters.Add(param);

    param = new OdbcParameter();
    param.DbType = DbType.Decimal;
    param.Value = 1;
    command.Parameters.Add(param);

    param = new OdbcParameter();
    param.DbType = DbType.Decimal;
    param.Value = 1;
    command.Parameters.Add(param);

    command.ExecuteNonQuery();

 }

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft