Export (0) Print
Expand All

OleDbParameter Class

Represents a parameter to an OleDbCommand and optionally its mapping to a DataSet column. This class cannot be inherited.

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

'Declaration
Public NotInheritable Class OleDbParameter _
	Inherits DbParameter _
	Implements ICloneable, IDbDataParameter, IDataParameter

The OleDbParameter type exposes the following members.

  NameDescription
Public methodOleDbParameterInitializes a new instance of the OleDbParameter class.
Public methodOleDbParameter(String, OleDbType)Initializes a new instance of the OleDbParameter class that uses the parameter name and data type.
Public methodOleDbParameter(String, Object)Initializes a new instance of the OleDbParameter class that uses the parameter name and the value of the new OleDbParameter.
Public methodOleDbParameter(String, OleDbType, Int32)Initializes a new instance of the OleDbParameter class that uses the parameter name, data type, and length.
Public methodOleDbParameter(String, OleDbType, Int32, String)Initializes a new instance of the OleDbParameter class that uses the parameter name, data type, length, and source column name.
Public methodOleDbParameter(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.
Public methodOleDbParameter(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.
Top

  NameDescription
Public propertyDbTypeGets or sets the DbType of the parameter. (Overrides DbParameter.DbType.)
Public propertyDirectionGets or sets a value that indicates whether the parameter is input-only, output-only, bidirectional, or a stored procedure return-value parameter. (Overrides DbParameter.Direction.)
Public propertyIsNullableGets or sets a value that indicates whether the parameter accepts null values. (Overrides DbParameter.IsNullable.)
Public propertyOleDbTypeGets or sets the OleDbType of the parameter.
Public propertyParameterNameGets or sets the name of the OleDbParameter. (Overrides DbParameter.ParameterName.)
Public propertyPrecisionGets or sets the maximum number of digits used to represent the Value property.
Public propertyScaleGets or sets the number of decimal places to which Value is resolved.
Public propertySizeGets or sets the maximum size, in bytes, of the data within the column. (Overrides DbParameter.Size.)
Public propertySourceColumnGets or sets the name of the source column mapped to the DataSet and used for loading or returning the Value. (Overrides DbParameter.SourceColumn.)
Public propertySourceColumnNullMappingSets or gets a value which indicates whether the source column is nullable. This allows DbCommandBuilder to correctly generate Update statements for nullable columns. (Overrides DbParameter.SourceColumnNullMapping.)
Public propertySourceVersionGets or sets the DataRowVersion to use when you load Value. (Overrides DbParameter.SourceVersion.)
Public propertyValueGets or sets the value of the parameter. (Overrides DbParameter.Value.)
Top

  NameDescription
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.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (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 methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Public methodResetDbTypeResets the type associated with this OleDbParameter. (Overrides DbParameter.ResetDbType.)
Public methodResetOleDbTypeResets the type associated with this OleDbParameter.
Public methodToStringGets a string that contains the ParameterName. (Overrides Object.ToString.)
Top

  NameDescription
Explicit interface implemetationPrivate methodICloneable.CloneFor a description of this member, see ICloneable.Clone.
Explicit interface implemetationPrivate propertyIDbDataParameter.PrecisionIndicates the precision of numeric parameters. (Inherited from DbParameter.)
Explicit interface implemetationPrivate propertyIDbDataParameter.ScaleFor a description of this member, see IDbDataParameter.Scale. (Inherited from DbParameter.)
Top

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()

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.

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 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


.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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.

Community Additions

ADD
Show:
© 2014 Microsoft