OleDbParameter Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a parameter to an OleDbCommand and optionally its mapping to a DataSet column. This class cannot be inherited.
public ref class OleDbParameter sealed : System::Data::Common::DbParameter, ICloneable
public ref class OleDbParameter sealed : MarshalByRefObject, ICloneable, System::Data::IDbDataParameter
[System.ComponentModel.TypeConverter(typeof(System.Data.OleDb.OleDbParameter+OleDbParameterConverter))]
public sealed class OleDbParameter : System.Data.Common.DbParameter, ICloneable
[System.ComponentModel.TypeConverter(typeof(System.Data.OleDb.OleDbParameterConverter))]
public sealed class OleDbParameter : MarshalByRefObject, ICloneable, System.Data.IDbDataParameter
[<System.ComponentModel.TypeConverter(typeof(System.Data.OleDb.OleDbParameter+OleDbParameterConverter))>]
type OleDbParameter = class
inherit DbParameter
interface IDataParameter
interface IDbDataParameter
interface ICloneable
[<System.ComponentModel.TypeConverter(typeof(System.Data.OleDb.OleDbParameterConverter))>]
type OleDbParameter = class
inherit MarshalByRefObject
interface IDbDataParameter
interface IDataParameter
interface ICloneable
[<System.ComponentModel.TypeConverter(typeof(System.Data.OleDb.OleDbParameter+OleDbParameterConverter))>]
type OleDbParameter = class
inherit DbParameter
interface ICloneable
interface IDbDataParameter
interface IDataParameter
Public NotInheritable Class OleDbParameter
Inherits DbParameter
Implements ICloneable
Public NotInheritable Class OleDbParameter
Inherits MarshalByRefObject
Implements ICloneable, IDbDataParameter
- Inheritance
- Inheritance
- Inheritance
- Attributes
- Implements
Examples
The following example creates multiple instances of OleDbParameter through the OleDbParameterCollection collection within the OleDbDataAdapter. These parameters are used to select data from the data source and place the data in the DataSet. This example assumes that a DataSet and an OleDbDataAdapter have already been created by using the appropriate schema, commands, and connection.
public DataSet GetDataSetFromAdapter(
DataSet dataSet, string connectionString, string queryString)
{
using (OleDbConnection connection =
new OleDbConnection(connectionString))
{
OleDbDataAdapter adapter =
new OleDbDataAdapter(queryString, connection);
// Set the parameters.
adapter.SelectCommand.Parameters.Add(
"@CategoryName", OleDbType.VarChar, 80).Value = "toasters";
adapter.SelectCommand.Parameters.Add(
"@SerialNum", OleDbType.Integer).Value = 239;
// Open the connection and fill the DataSet.
try
{
connection.Open();
adapter.Fill(dataSet);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// The connection is automatically closed when the
// code exits the using block.
}
return dataSet;
}
Public Function GetDataSetFromAdapter( _
ByVal dataSet As DataSet, ByVal connectionString As String, _
ByVal queryString As String) As DataSet
Using connection As New OleDbConnection(connectionString)
Dim adapter As New OleDbDataAdapter(queryString, connection)
' Set the parameters.
adapter.SelectCommand.Parameters.Add( _
"@CategoryName", OleDbType.VarChar, 80).Value = "toasters"
adapter.SelectCommand.Parameters.Add( _
"@SerialNum", OleDbType.Integer).Value = 239
' Open the connection and fill the DataSet.
Try
connection.Open()
adapter.Fill(dataSet)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
' The connection is automatically closed when the
' code exits the Using block.
End Using
Return dataSet
End Function
Remarks
The OLE DB.NET Framework Data Provider uses positional parameters that are marked with a question mark (?) instead of named parameters.
When querying an Oracle database using the Microsoft OLE DB Provider for Oracle (MSDAORA) and the OLE DB.NET Framework Data Provider, using the LIKE
clause to query values in fixed-length fields may not return all expected matches. The reason is that when Oracle matches values for fixed-length fields in a LIKE
clause, it matches the entire length of the string, including any padding trailing spaces. For example, if a table in an Oracle database contains a field named "Field1" that is defined as char(3)
, and you enter the value "a" into a row of that table, the following code does not return the row.
Dim queryString As String = "SELECT * FROM Table1 WHERE Field1 LIKE ?"
Dim command As OleDbCommand = New OleDbCommand(queryString, connection)
command.Parameters.Add("@p1", OleDbType.Char, 3).Value = "a"
Dim reader As OleDbDataReader = command.ExecuteReader()
string queryString = "SELECT * FROM Table1 WHERE Field1 LIKE ?";
OleDbCommand command = new OleDbCommand(queryString, connection);
command.Parameters.Add("@p1", OleDbType.Char, 3).Value = "a";
OleDbDataReader reader = command.ExecuteReader();
This is because Oracle stores the column value as "a " (padding "a", with trailing spaces, to the fixed field length of 3), which Oracle does not treat as a match for the parameter value of "a" in the case of a LIKE
comparison of fixed-length fields.
To resolve this problem, append a percentage ("%") wildcard character to the parameter value ("a%"
), or use an SQL =
comparison instead.
Constructors
OleDbParameter() |
Initializes a new instance of the OleDbParameter class. |
OleDbParameter(String, Object) |
Initializes a new instance of the OleDbParameter class that uses the parameter name and the value of the new OleDbParameter. |
OleDbParameter(String, OleDbType, Int32, ParameterDirection, Boolean, Byte, Byte, String, DataRowVersion, Object) |
Initializes a new instance of the OleDbParameter class that uses the parameter name, data type, length, source column name, parameter direction, numeric precision, and other properties. |
OleDbParameter(String, OleDbType, Int32, ParameterDirection, Byte, Byte, String, DataRowVersion, Boolean, Object) |
Initializes a new instance of the OleDbParameter class that uses the parameter name, data type, length, source column name, parameter direction, numeric precision, and other properties. |
OleDbParameter(String, OleDbType, Int32, String) |
Initializes a new instance of the OleDbParameter class that uses the parameter name, data type, length, and source column name. |
OleDbParameter(String, OleDbType, Int32) |
Initializes a new instance of the OleDbParameter class that uses the parameter name, data type, and length. |
OleDbParameter(String, OleDbType) |
Initializes a new instance of the OleDbParameter class that uses the parameter name and data type. |
Properties
DbType |
Gets or sets the DbType of the parameter. |
Direction |
Gets or sets a value that indicates whether the parameter is input-only, output-only, bidirectional, or a stored procedure return-value parameter. |
IsNullable |
Gets or sets a value that indicates whether the parameter accepts null values. |
OleDbType |
Gets or sets the OleDbType of the parameter. |
ParameterName |
Gets or sets the name of the OleDbParameter. |
Precision |
Gets or sets the maximum number of digits used to represent the Value property. |
Scale |
Gets or sets the number of decimal places to which Value is resolved. |
Size |
Gets or sets the maximum size, in bytes, of the data within the column. |
SourceColumn |
Gets or sets the name of the source column mapped to the DataSet and used for loading or returning the Value. |
SourceColumnNullMapping |
Gets or sets a value which indicates whether the source column is nullable. This allows DbCommandBuilder to correctly generate Update statements for nullable columns. |
SourceVersion |
Gets or sets the DataRowVersion to use when you load Value. |
Value |
Gets or sets the value of the parameter. |
Methods
CreateObjRef(Type) |
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject) |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetLifetimeService() |
Obsolete.
Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject) |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
InitializeLifetimeService() |
Obsolete.
Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
MemberwiseClone(Boolean) |
Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject) |
ResetDbType() |
Resets the type associated with this OleDbParameter. |
ResetOleDbType() |
Resets the type associated with this OleDbParameter. |
ToString() |
Gets a string that contains the ParameterName. |
Explicit Interface Implementations
ICloneable.Clone() |
For a description of this member, see Clone(). |
IDbDataParameter.Precision |
Indicates the precision of numeric parameters. (Inherited from DbParameter) |
IDbDataParameter.Scale |
For a description of this member, see Scale. (Inherited from DbParameter) |
Applies to
See also
.NET