An OracleParameterCollection
class represents a collection of all parameters relevant to an OracleCommand
object and their mappings to DataSet
columns.
System.Object
System.MarshalByRefObject
System.Data.Common.DbParameterCollection
Oracle.DataAccess.Client.OracleParameterCollection
// C# public sealed class OracleParameterCollection : DbParameterCollection, IDataParameterCollection, IList, ICollection, IEnumerable
Provider | ODP.NET, Unmanaged Driver | ODP.NET, Managed Driver |
Assembly | Oracle.DataAccess.dll |
Oracle.ManagedDataAccess.dll |
Namespace | Oracle.DataAccess.Client |
Oracle.ManagedDataAccess.Client |
.NET Framework | 3.5, 4.0, 4.5 | 4.0, 4.5 |
All public static methods are thread-safe, although instance methods do not guarantee thread safety.
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.
// 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(); } }
See Also:
OracleParameterCollection
members are listed in the following tables.
OracleParameterCollection Static Methods
OracleParameterCollection
static methods are listed in Table 6-103.
Table 6-103 OracleParameterCollection Static Methods
Method | Description |
---|---|
|
Inherited from |
OracleParameterCollection Properties
OracleParameterCollection
properties are listed in Table 6-104.
Table 6-104 OracleParameterCollection Properties
Property | Description |
---|---|
Specifies the number of |
|
Gets and sets the |
OracleParameterCollection Public Methods
OracleParameterCollection
public methods are listed in Table 6-105.
Table 6-105 OracleParameterCollection Public Methods
Public Method | Description |
---|---|
Adds objects to the collection (Overloaded) |
|
Adds elements to the end of the |
|
Removes all the |
|
Indicates whether or not objects exist in the collection (Overloaded) |
|
Copies |
|
|
Inherited from |
|
Inherited from |
|
Inherited from |
|
Inherited from |
|
Inherited from |
|
Inherited from |
Returns the |
|
Inserts the supplied |
|
Removes objects from the collection |
|
Removes objects from the collection by location (Overloaded) |
|
|
Inherited from |
The OracleParameterCollection
static method is listed in Table 6-106.
OracleParameterCollection
properties are listed in Table 6-107.
Table 6-107 OracleParameterCollection Properties
Property | Description |
---|---|
Specifies the number of |
|
Gets and sets the |
See Also:
This property specifies the number of OracleParameter
objects in the collection.
// C# public override int Count {get;}
The number of OracleParameter
objects.
ICollection
Default = 0
Item
gets and sets the OracleParameter
object.
This property gets and sets the OracleParameter
object at the index specified by the supplied parameterIndex
.
This property gets and sets the OracleParameter
object using the parameter name specified by the supplied parameterName
.
This property gets and sets the OracleParameter
object at the index specified by the supplied parameterIndex
.
// C# public object Item[int parameterIndex] {get; set;}
An object.
IList
IndexOutOfRangeException
- The supplied index does not exist.
The OracleParameterCollection
class is a zero-based index.
This property gets and sets the OracleParameter
object using the parameter name specified by the supplied parameterName
.
// C# public OracleParameter Item[string parameterName] {get; set;};
An OracleParameter
.
IDataParameterCollection
IndexOutOfRangeException
- The supplied parameter name does not exist.
OracleParameterCollection
public methods are listed in Table 6-108.
Table 6-108 OracleParameterCollection Public Methods
Public Method | Description |
---|---|
Adds objects to the collection (Overloaded) |
|
Adds elements to the end of the |
|
Removes all the |
|
Indicates whether or not objects exist in the collection (Overloaded) |
|
Copies |
|
|
Inherited from |
|
Inherited from |
|
Inherited from |
|
Inherited from |
|
Inherited from |
|
Inherited from |
Returns the |
|
Inserts the supplied |
|
Removes objects from the collection |
|
Removes objects from the collection by location (Overloaded) |
|
|
Inherited from |
See Also:
Add
adds objects to the collection.
This method adds the supplied object to the collection.
This method adds the supplied OracleParameter
object to the collection.
This method adds an OracleParameter
object to the collection using the supplied name and object value.
This method adds an OracleParameter
object to the collection using the supplied name and database type.
Add(string, OracleDbType, ParameterDirection)
This method adds an OracleParameter
object to the collection using the supplied name, database type, and direction.
Add(string, OracleDbType, object, ParameterDirection)
This method adds an OracleParameter
object to the collection using the supplied name, database type, parameter value, and direction.
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.
Add(string, OracleDbType, int)
This method adds an OracleParameter
object to the collection using the supplied name, database type, and size.
Add (string, OracleDbType, int, string)
This method adds an OracleParameter
object to the collection using the supplied name, database type, size, and source column.
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.
This method adds the supplied object to the collection.
// C#
public override int Add(object obj);
obj
The supplied object.
The index at which the new OracleParameter
is added.
IList
InvalidCastException
- The supplied obj
cannot be cast to an OracleParameter
object.
This method adds the supplied OracleParameter
object to the collection.
// C#
public OracleParameter Add(OracleParameter paramObj);
paramObj
The supplied OracleParameter
object.
The newly created OracleParameter
object which was added to the collection.
This method adds an OracleParameter
object to the collection using the supplied name and object value
// C# public OracleParameter Add(string name, object val);
name
The parameter name.
val
The OracleParameter
value.
The newly created OracleParameter
object which was added to the collection.
This method adds an OracleParameter
object to the collection using the supplied name and database type.
// C# public OracleParameter Add(string name, OracleDbType dbType);
name
The parameter name.
dbType
The data type of the OracleParameter
.
The newly created OracleParameter
object which was added to the collection.
This method adds an OracleParameter
object to the collection using the supplied name, database type, and direction.
// C# public OracleParameter Add(string name, OracleDbType dbType, ParameterDirection direction);
name
The parameter name.
dbType
The data type of the OracleParameter
.
direction
The OracleParameter
direction.
The newly created OracleParameter
object which was added to the collection.
This method adds an OracleParameter
object to the collection using the supplied name, database type, parameter value, and direction.
// C# public OracleParameter Add(string name, OracleDbType dbType, object val, ParameterDirection dir);
name
The parameter name.
dbType
The data type of the OracleParameter
.
val
The OracleParameter
value.
dir
The ParameterDirection
value.
The newly created OracleParameter
object which was added to the collection.
// 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(); } }
This method adds an OracleParameter
object to the collection using the supplied name, database type, size, parameter value, and direction.
// C# public OracleParameter Add(string name, OracleDbType dbType, int size, object val, ParameterDirection dir;
name
The parameter name.
dbType
The data type of the OracleParameter
.
size
The size of OracleParameter
.
val
The OracleParameter
value.
dir
The ParameterDirection
value.
The newly created OracleParameter
object which was added to the collection.
This method adds an OracleParameter
object to the collection using the supplied name, database type, and size.
// C# public OracleParameter Add(string name, OracleDbType dbType, int size);
name
The parameter name.
dbType
The data type of the OracleParameter
.
size
The size of OracleParameter
.
The newly created OracleParameter
object which was added to the collection.
// 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(); } }
This method adds an OracleParameter
object to the collection using the supplied name, database type, size, and source column.
// C# public OracleParameter Add(string name, OracleDbType dbType, int size, string srcColumn);
name
The parameter name.
dbType
The data type of the OracleParameter
.
size
The size of OracleParameter
.
srcColumn
The name of the source column.
An OracleParameter
.
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.
// C# public OracleParameter Add(string name, OracleDbType dbType, int size, ParameterDirection dir, bool isNullable, byte precision, byte scale, string srcColumn, DataRowVersion version, object val);
name
The parameter name.
dbType
The data type of the OracleParameter
.
size
The size of OracleParameter
.
dir
The ParameterDirection
value.
isNullable
An indicator that specifies if the parameter
value can be null
.
precision
The precision of the parameter
value.
scale
The scale of the parameter
value.
srcColumn
The name of the source column.
version
The DataRowVersion
value.
val
The parameter
value.
The newly created OracleParameter
object which was added to the collection.
ArgumentException
- The type of supplied val
does not belong to the type of Value
property in any of the ODP.NET Types.
This method adds elements to the end of the OracleParameterCollection
.
// C#
public override void AddRange(Array paramArray );
paramArray
An array of OracleParameter
objects.
ArgumentNullException
- The input parameter is null.
This method removes all the OracleParameter
objects from the collection.
// C# public override void Clear();
IList
// 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
indicates whether or not the supplied object exists in the collection.
This method indicates whether or not the supplied object exists in the collection.
This method indicates whether or not an OracleParameter
object exists in the collection using the supplied string.
This method indicates whether or not the supplied object exists in the collection.
// C#
public override bool Contains(object obj)
obj
The object.
A bool
that indicates whether or not the OracleParameter
specified is inside the collection.
IList
InvalidCastException
- The supplied obj
is not an OracleParameter
object.
Returns true
if the collection contains the OracleParameter
object; otherwise, returns false
.
// 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(); } }
This method indicates whether or not an OracleParameter
object exists in the collection using the supplied string.
// C#
public override bool Contains(string name);
name
The name of OracleParameter
object.
Returns true
if the collection contains the OracleParameter
object with the specified parameter name; otherwise, returns false
.
IDataParameterCollection
// 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(); } }
This method copies OracleParameter
objects from the collection, starting with the supplied index
to the supplied array
.
// C# public override void CopyTo(Array array, int index);
array
The specified array.
index
The array index.
ICollection
IndexOf
returns the index of the OracleParameter
object in the collection.
This method returns the index of the OracleParameter
object in the collection.
This method returns the index
of the OracleParameter
object with the specified name in the collection.
This method returns the index of the OracleParameter
object in the collection.
// C#
public override int IndexOf(object obj);
obj
The specified object.
Returns the index of the OracleParameter
object in the collection.
IList
InvalidCastException
- The supplied obj
cannot be cast to an OracleParameter
object.
Returns the index
of the supplied OracleParameter
obj
in the collection.
This method returns the index
of the OracleParameter
object with the specified name in the collection.
// C#
public override int IndexOf(String name);
name
The name of parameter.
Returns the index
of the supplied OracleParameter
in the collection.
IDataParameterCollection
This method inserts the supplied OracleParameter
object to the collection at the specified index
.
// C# public override void Insert(int index, object obj);
index
The specified index.
obj
The OracleParameter
object.
IList
An InvalidCastException
is thrown if the supplied obj
cannot be cast to an OracleParameter
object.
This method removes the supplied OracleParameter
from the collection.
// C#
public override void Remove(object obj);
obj
The specified object to remove.
IList
InvalidCastException
- The supplied obj
cannot be cast to an OracleParameter
object.
// 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
removes the OracleParameter
object from the collection by location.
This method removes from the collection the OracleParameter
object located at the index specified by the supplied index.
This method removes from the collection the OracleParameter
object specified by the supplied name.
This method removes from the collection the OracleParameter
object located at the index specified by the supplied index.
// C#
public override void RemoveAt(int index);
index
The specified index from which the OracleParameter
is to be removed.
IList