Skip Headers

Oracle® Data Provider for .NET Developer's Guide
Release 9.2.0.4

Part Number B10961-01
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to beginning of chapter Go to next page

Oracle.DataAccess.Client Namespace, 16 of 30


OracleParameterCollection Class

An OracleParameterCollection class represents a collection of all parameters relevant to an OracleCommand object and their mappings to DataSet columns.

Class Inheritance

Object

  MarshalByRefObject

    OracleParameterCollection

Declaration
// C#
public sealed class OracleParameterCollection : MarshalByRefObject, 
  IDataParameterCollection, IList, ICollection, IEnumerable
Thread Safety

All public static methods are thread-safe, although instance methods do not guarantee thread safety.

Remarks

The position of an OracleParameter added into the OracleParameterCollection is the binding position in the SQL statement. Position is 0-based and is used only for positional binding. If named binding is used, the position of an OracleParameter in the OracleParameterCollection is ignored.

Example
// C#
string conStr = "User Id=scott;Password=tiger;Data Source=oracle";

// Create the OracleConnection
OracleConnection con = new OracleConnection(conStr);
con.Open();

// Create the OracleCommand
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;

// Create OracleParameter
OracleParameter [] prm = new OracleParameter[3];

// Bind parameters
prm[0] = cmd.Parameters.Add("paramEmpno", OracleDbType.Decimal, 1234, 
    ParameterDirection.Input);
prm[1] = cmd.Parameters.Add("paramEname", OracleDbType.Varchar2, 
    "Client", ParameterDirection.Input);
prm[2] = cmd.Parameters.Add("paramDeptNo", OracleDbType.Decimal, 
    10, ParameterDirection.Input);

cmd.CommandText = "insert into emp(empno, ename, deptno) values(:1, :2, :3)";
cmd.ExecuteNonQuery();

// Remove OracleParameter objects from the collection
cmd.Parameters.Clear();

// Dispose OracleCommand object
cmd.Dispose();

// Close and Dispose OracleConnection object
con.Close();
con.Dispose();

Requirements

Namespace: Oracle.DataAccess.Client

Assembly: Oracle.DataAccess.dll

See Also:

OracleParameterCollection Members

OracleParameterCollection members are listed in the following tables:

OracleParameterCollection Static Methods

OracleParameterCollection static methods are listed in Table 4-92.

Table 4-92 OracleParameterCollection Static Methods
Methods Description

Equals

Inherited from Object (Overloaded)

OracleParameterCollection Properties

OracleParameterCollection properties are listed in Table 4-93.

Table 4-93 OracleParameterCollection Properties  
Name Description

Count

Specifies the number of OracleParameters in the collection

Item

Gets and sets the OracleParameter object (Overloaded)

OracleParameterCollection Public Methods

OracleParameterCollection public methods are listed in Table 4-94.

Table 4-94 OracleParameterCollection Public Methods  
Public Method Description

Add

Adds objects to the collection (Overloaded)

Clear

Removes all the OracleParameter objects from the collection

Contains

Indicates whether objects exist in the collection (Overloaded)

CopyTo

Copies OracleParameter objects from the collection, starting with the supplied index to the supplied array

CreateObjRef

Inherited from MarshalByRefObject

Equals

Inherited from Object (Overloaded)

GetHashCode

Inherited from Object

GetLifetimeService

Inherited from MarshalByRefObject

GetType

Inherited from Object

InitializeLifetimeService

Inherited from MarshalByRefObject

IndexOf

Returns the index of the objects in the collection (Overloaded)

Insert

Inserts the supplied OracleParameter to the collection at the specified index

Remove

Removes objects from the collection

RemoveAt

Removes objects from the collection by location (Overloaded)

ToString

Inherited from Object

See Also:

OracleParameterCollection Static Methods

OracleParameterCollection static methods are listed in Table 4-95.

Table 4-95 OracleParameterCollection Static Methods
Methods Description

Equals

Inherited from Object (Overloaded)

See Also:

OracleParameterCollection Properties

OracleParameterCollection properties are listed in Table 4-96.

Table 4-96 OracleParameterCollection Properties  
Name Description

Count

Specifies the number of OracleParameters in the collection

Item

Gets and sets the OracleParameter object (Overloaded)

See Also:

Count

This property specifies the number of OracleParameter objects in the collection.

Declaration
// C#
public int Count {get;}
Property Value

The number of OracleParameter objects.

Implements

ICollection

Remarks

Default = 0

See Also:

Item

Item gets and sets the OracleParameter object.

Overload List:

Item[int]

This property gets and sets the OracleParameter object at the index specified by the supplied parameterIndex.

Declaration
// C#
public object Item[int parameterIndex] {get; set;}
Property Value

An object.

Implements

IList

Exceptions

IndexOutOfRangeException - The supplied index does not exist.

Remarks

The OracleParameterCollection class is a zero-based index.

See Also:

Item[string]

This property gets and sets the OracleParameter object using the parameter name specified by the supplied parameterName.

Declaration
// C#
public OracleParameter Item[string parameterName] {get; set;};
Property Value

An OracleParameter.

Implements

IDataParameterCollection

Exceptions

IndexOutOfRangeException - The supplied parameter name does not exist.

See Also:

OracleParameterCollection Public Methods

OracleParameterCollection public methods are listed in Table 4-97.

Table 4-97 OracleParameterCollection Public Methods  
Public Method Description

Add

Adds objects to the collection (Overloaded)

Clear

Removes all the OracleParameter objects from the collection

Contains

Indicates whether objects exist in the collection (Overloaded)

CopyTo

Copies OracleParameter objects from the collection, starting with the supplied index to the supplied array

CreateObjRef

Inherited from MarshalByRefObject

Equals

Inherited from Object (Overloaded)

GetHashCode

Inherited from Object

GetLifetimeService

Inherited from MarshalByRefObject

GetType

Inherited from Object

InitializeLifetimeService

Inherited from MarshalByRefObject

IndexOf

Returns the index of the objects in the collection (Overloaded)

Insert

Inserts the supplied OracleParameter to the collection at the specified index

Remove

Removes objects from the collection

RemoveAt

Removes objects from the collection by location (Overloaded)

ToString

Inherited from Object

See Also:

Add

Add adds objects to the collection.

Overload List:

Add(object)

This method adds the supplied object to the collection.

Declaration
// C#
public int Add(object obj);
Parameters
Return Value

The index at which the new OracleParameter is added.

Implements

IList

Remarks

InvalidCastException - The supplied obj cannot be cast to an OracleParameter object.

See Also:

Add(OracleParameter)

This method adds the supplied OracleParameter object to the collection.

Declaration
// C#
public OracleParameter Add(OracleParameter paramObj);
Parameters
Return Value

The newly created OracleParameter object which was added to the collection.

See Also:

Add(string, object)

This method adds an OracleParameter object to the collection using the supplied name and object value

Declaration
// C#
public OracleParameter Add(string name, object val);
Parameters
Return Value

The newly created OracleParameter object which was added to the collection.

See Also:

Add(string, OracleDbType)

This method adds an OracleParameter object to the collection using the supplied name and database type.

Declaration
// C#
public OracleParameter Add(string name, OracleDbType dbType);
Parameters
Return Value

The newly created OracleParameter object which was added to the collection.

See Also:

Add(string, OracleDbType, ParameterDirection)

This method adds an OracleParameter object to the collection using the supplied name, database type, and direction.

Declaration
// C#
public OracleParameter Add(string name, OracleDbType dbType, ParameterDirection 
direction);
Parameters
Return Value

The newly created OracleParameter object which was added to the collection.

See Also:

Add(string, OracleDbType, object, ParameterDirection)

This method adds an OracleParameter object to the collection using the supplied name, database type, parameter value, and direction.

Declaration
// C#
public OracleParameter Add(string name, OracleDbType dbType, object val,
 ParameterDirection dir);
Parameters
Return Value

The newly created OracleParameter object which was added to the collection.

Example
// C#
...
OracleParameter prm = new OracleParameter();
prm = cmd.Parameters.Add("paramEmpno", OracleDbType.Decimal, 1234, 
   ParameterDirection.Input);

cmd.CommandText = "insert into NumTable(numcol) values(:1)";
cmd.ExecuteNonQuery();
...

See Also:

Add(string, OracleDbType, int, object, ParameterDirection)

This method adds an OracleParameter object to the collection using the supplied name, database type, size, parameter value, and direction.

Declaration
// C#
public OracleParameter Add(string name, OracleDbType dbType, int size, 
   object val, ParameterDirection dir;
Parameters
Return Value

The newly created OracleParameter object which was added to the collection.

See Also:

Add(string, OracleDbType, int)

This method adds an OracleParameter object to the collection using the supplied name, database type, and size.

Declaration
// C#
public OracleParameter Add(string name, OracleDbType dbType, int size);
Parameters
Return Value

The newly created OracleParameter object which was added to the collection.

Example
// C#
...
OracleParameter prm = new OracleParameter();
prm = cmd.Parameters.Add("param1", OracleDbType.Decimal, 10);
prm.Direction = ParameterDirection.Input;
prm.Value = 1111;

cmd.CommandText = "insert into NumTable(numcol) values(:1)";
cmd.ExecuteNonQuery();
...

See Also:

Add (string, OracleDbType, int, string)

This method adds an OracleParameter object to the collection using the supplied name, database type, size, and source column.

Declaration
// C#
public OracleParameter Add(string name, OracleDbType dbType, int size, 
  string srcColumn);
Parameters
Return Value

An OracleParameter.

See Also:

Add(string, OracleDbType, int, ParameterDirection, bool, byte, byte, string, DataRowVersion, object)

This method adds an OracleParameter object to the collection using the supplied name, database type, size, direction, null indicator, precision, scale, source column, source version, and parameter value.

Declaration
// C#
public OracleParameter Add(string name, OracleDbType dbType, int size,
  ParameterDirection dir, bool isNullable, byte precision, 
  byte scale, string srcColumn, DataRowVersion version, object val);
Parameters
Return Value

The newly created OracleParameter object which was added to the collection.

Exceptions

ArgumentException - The type of supplied val does not belong to the type of Value property in any of the ODP.NET Types.

See Also:

Clear

This method removes all the OracleParameter objects from the collection.

Declaration
// C#
public void Clear();
Implements

IList

Example
// C#
...
OracleParameter [] prm = new OracleParameter[3];

prm[0] = cmd.Parameters.Add("paramEmpno", OracleDbType.Decimal, 
   1234, ParameterDirection.Input);
prm[1] = cmd.Parameters.Add("paramEname", OracleDbType.Varchar2, 
   "Client", ParameterDirection.Input);
prm[2] = cmd.Parameters.Add("paramDeptNo", OracleDbType.Decimal, 10,
    ParameterDirection.Input);

cmd.CommandText = "insert into emp(empno, ename, deptno) values(:1,:2, :3)";
cmd.ExecuteNonQuery();

// This method removes all the parameters from the parameter collection.
cmd.Parameters.Clear();
...

See Also:

Contains

Contains indicates whether the supplied object exists in the collection.

Overload List:

Contains(object)

This method indicates whether the supplied object exists in the collection.

Declaration
// C#
public bool Contains(object obj)
Parameters
Return Value

A bool that indicates whether or not the OracleParameter specified is inside the collection.

Implements

IList

Exceptions

InvalidCastException - The supplied obj is not an OracleParameter object.

Remarks

Returns true if the collection contains the OracleParameter object; otherwise, returns false.

Example
...
prm = cmd.Parameters.Add("param1", OracleDbType.Decimal, 1234, 
     ParameterDirection.Input);
if (cmd.Parameters.Contains((Object)prm))
// This method removes a particular parameter from the parameter collection.
cmd.Parameters.Remove((Object) prm);
...

See Also:

Contains(string)

This method indicates whether an OracleParameter object exists in the collection using the supplied string.

Declaration
// C#
public bool Contains(string name);
Parameters
Return Value

Returns true if the collection contains the OracleParameter object with the specified parameter name; otherwise, returns false.

Implements

IDataParameterCollection

Example
...
prm = cmd.Parameters.Add("param1", OracleDbType.Decimal, 1234, +
     ParameterDirection.Input);
if (cmd.Parameters.Contains((Object)prm))
// This method removes a particular parameter from the parameter collection.
cmd.Parameters.Remove((Object) prm);
...

See Also:

CopyTo

This method copies OracleParameter objects from the collection, starting with the supplied index to the supplied array.

Declaration
// C#
public void CopyTo(Array array, int index);
Parameters
Implements

ICollection

See Also:

IndexOf

IndexOf returns the index of the OracleParameter object in the collection.

Overload List:

IndexOf(object)

This method returns the index of the OracleParameter object in the collection.

Declaration
// C#
public int IndexOf(object obj);
Parameters
Return Value

Returns the index of the OracleParameter object in the collection.

Implements

IList

Exceptions

InvalidCastException - The supplied obj cannot be cast to an OracleParameter object.

Remarks

Returns the index of the supplied OracleParameter obj in the collection.

See Also:

IndexOf(String)

This method returns the index of the OracleParameter object with the specified name in the collection.

Declaration
// C#
public int IndexOf(String name);
Parameters
Return Value

Returns the index of the supplied OracleParameter in the collection.

Implements

IDataParameterCollection

See Also:

Insert

This method inserts the supplied OracleParameter object to the collection at the specified index.

Declaration
// C#
public void Insert(int index, object obj);
Parameters
Implements

IList

Remarks

An InvalidCastException is thrown if the supplied obj cannot be cast to an OracleParameter object.

See Also:

Remove

This method removes the supplied OracleParameter from the collection.

Declaration
// C#
public void Remove(object obj);
Parameters
Implements

IList

Exceptions

InvalidCastException - The supplied obj cannot be cast to an OracleParameter object.

Example
...
prm = cmd.Parameters.Add("param1", OracleDbType.Decimal, 1234, 
     ParameterDirection.Input);
if (cmd.Parameters.Contains((Object)prm))
// This method removes a particular parameter from the parameter collection.
cmd.Parameters.Remove((Object) prm);
...

See Also:

RemoveAt

RemoveAt removes the OracleParameter object from the collection by location.

Overload List:

RemoveAt(int)

This method removes from the collection the OracleParameter object located at the index specified by the supplied index.

Declaration
// C#
public void RemoveAt(int index);
Parameters
Implements

IList

See Also:

RemoveAt(String)

This method removes from the collection the OracleParameter object specified by the supplied name.

Declaration
// C#
public void RemoveAt(String name);
Parameters
Implements

IDataParameterCollection

See Also:


Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 2002, 2003 Oracle Corporation.

All Rights Reserved.
Go To Table Of Contents
Contents
Go To Index
Index