Skip Headers
Oracle® Data Provider for .NET Developer's Guide
10g Release 2 (10.2)

Part Number B14307-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page
Previous
Go to next page
Next
View PDF

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#
 
using System;
using System.Data;
using Oracle.DataAccess.Client; 
 
class OracleParameterCollectionSample
{
  static void Main()
  {
    string constr = "User Id=scott;Password=tiger;Data Source=oracle";
    OracleConnection con = new OracleConnection(constr);
    con.Open();
 
    OracleParameter[] prm = new OracleParameter[3];
 
    // Create OracleParameter objects through OracleParameterCollection
    OracleCommand cmd = con.CreateCommand();
 
    cmd.CommandText = "select max(empno) from emp";
    int maxno = int.Parse(cmd.ExecuteScalar().ToString());
 
    prm[0] = cmd.Parameters.Add("paramEmpno", OracleDbType.Decimal, 
      maxno + 10, 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();
 
    Console.WriteLine("Record for employee id {0} has been inserted.", 
      maxno + 10);
 
    // Remove all parameters from OracleParameterCollection
    cmd.Parameters.Clear();
 
    prm[0].Dispose();
    prm[1].Dispose();
    prm[2].Dispose();
    cmd.Dispose();
 
    con.Close();
    con.Dispose();
  }
}

Requirements

Namespace: Oracle.DataAccess.Client

Assembly: Oracle.DataAccess.dll


OracleParameterCollection Members

OracleParameterCollection members are listed in the following tables:

OracleParameterCollection Static Methods

OracleParameterCollection static methods are listed in Table 5-76.

Table 5-76 OracleParameterCollection Static Methods

Methods Description
Equals Inherited from Object (Overloaded)

OracleParameterCollection Properties

OracleParameterCollection properties are listed in Table 5-77.

Table 5-77 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 5-78.

Table 5-78 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 or not 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


OracleParameterCollection Static Methods

The OracleParameterCollection static method is listed in Table 5-79.

Table 5-79 OracleParameterCollection Static Method

Method Description
Equals Inherited from Object (Overloaded)


OracleParameterCollection Properties

OracleParameterCollection properties are listed in Table 5-80.

Table 5-80 OracleParameterCollection Properties

Name Description
Count Specifies the number of OracleParameters in the collection
Item Gets and sets the OracleParameter object (Overloaded)

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

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.

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.


OracleParameterCollection Public Methods

OracleParameterCollection public methods are listed in Table 5-81.

Table 5-81 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 or not 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

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.

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.

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.

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.

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.

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#
 
using System;
using System.Data;
using Oracle.DataAccess.Client;
 
class AddSample
{
  static void Main()
  {
    OracleCommand cmd = new OracleCommand();
 
    // Add parameter to the OracleParameterCollection
    OracleParameter prm = cmd.Parameters.Add(
      "MyParam", OracleDbType.Decimal, 1, ParameterDirection.Input);
 
    // Prints "cmd.Parameters.Count = 1"
    Console.WriteLine("cmd.Parameters.Count = " + cmd.Parameters.Count);
 
    prm.Dispose();
    cmd.Dispose();
  }
}

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.

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#
 
using System;
using Oracle.DataAccess.Client;
 
class AddSample
{
  static void Main()
  {
    OracleCommand cmd = new OracleCommand();
 
    // Add parameter to the OracleParameterCollection
    OracleParameter prm = cmd.Parameters.Add(
      "MyParam", OracleDbType.Varchar2, 10);
 
    // Prints "cmd.Parameters.Count = 1"
    Console.WriteLine("cmd.Parameters.Count = " + cmd.Parameters.Count);
 
    prm.Dispose();
    cmd.Dispose();
  }
}

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.

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.

Clear

This method removes all the OracleParameter objects from the collection.

Declaration

// C#
public void Clear();

Implements

IList

Example

// C#
 
using System;
using Oracle.DataAccess.Client;
 
class ClearSample
{
  static void Main()
  {
    OracleCommand cmd = new OracleCommand();
 
    // Add parameter to the OracleParameterCollection
    OracleParameter prm = cmd.Parameters.Add("MyParam", OracleDbType.Decimal);
 
    // Prints "cmd.Parameters.Count = 1"
    Console.WriteLine("cmd.Parameters.Count = " + cmd.Parameters.Count);
 
    // Clear all parameters in the OracleParameterCollection
    cmd.Parameters.Clear();
 
    // Prints "cmd.Parameters.Count = 0"
    Console.WriteLine("cmd.Parameters.Count = " + cmd.Parameters.Count);
 
    prm.Dispose();
    cmd.Dispose();
  }
}

Contains

Contains indicates whether or not the supplied object exists in the collection.

Overload List:

Contains(object)

This method indicates whether or not 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

// C#
 
using System;
using Oracle.DataAccess.Client;
 
class ContainsSample
{
  static void Main()
  {
    OracleCommand cmd = new OracleCommand();
 
    // Add parameter to the OracleParameterCollection
    OracleParameter prm1 = cmd.Parameters.Add("MyParam", OracleDbType.Decimal);
 
    // Check if the OracleParameterCollection contains prm1
    bool bContains = cmd.Parameters.Contains(prm1);
 
    // Prints "bContains = True"
    Console.WriteLine("bContains = " + bContains);
 
    OracleParameter prm2 = new OracleParameter();
 
    // Check if the OracleParameterCollection contains prm2
    bContains = cmd.Parameters.Contains(prm2);
 
    // Prints "bContains = False"
    Console.WriteLine("bContains = " + bContains);
 
    prm1.Dispose();
    prm2.Dispose();
    cmd.Dispose();
  }
}

Contains(string)

This method indicates whether or not 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

// C#
 
using System;
using Oracle.DataAccess.Client;
 
class ContainsSample
{
  static void Main()
  {
    OracleCommand cmd = new OracleCommand();
 
    // Add parameter to the OracleParameterCollection
    OracleParameter prm = cmd.Parameters.Add("MyParam", OracleDbType.Decimal);
 
    // Check if the OracleParameterCollection contains "MyParam"
    bool bContains = cmd.Parameters.Contains("MyParam");
 
    // Prints "bContains = True"
    Console.WriteLine("bContains = " + bContains);
 
    // Check if the OracleParameterCollection contains "NoParam"
    bContains = cmd.Parameters.Contains("NoParam");
 
    // Prints "bContains = False"
    Console.WriteLine("bContains = " + bContains);
 
    prm.Dispose();
    cmd.Dispose();
  }
}

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

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.

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

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.

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

// C#
 
using System;
using Oracle.DataAccess.Client;
 
class RemoveSample
{
  static void Main()
  {
    OracleCommand cmd = new OracleCommand();
 
    // Add 2 parameters to the OracleParameterCollection
    OracleParameter prm1 = cmd.Parameters.Add("MyParam1", OracleDbType.Decimal);
    OracleParameter prm2 = cmd.Parameters.Add("MyParam2", OracleDbType.Decimal);
 
    // Prints "cmd.Parameters.Count = 2"
    Console.WriteLine("cmd.Parameters.Count = " + cmd.Parameters.Count);
 
    // Remove the 1st parameter from the OracleParameterCollection
    cmd.Parameters.Remove(prm1);
 
    // Prints "cmd.Parameters.Count = 1"
    Console.WriteLine("cmd.Parameters.Count = " + cmd.Parameters.Count);
 
    // Prints "cmd.Parameters[0].ParameterName = MyParam2"
    Console.WriteLine("cmd.Parameters[0].ParameterName = " + 
      cmd.Parameters[0].ParameterName);
 
    prm1.Dispose();
    prm2.Dispose();
    cmd.Dispose();
  }
}

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

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