OdbcParameter Class

OdbcParameter Class

 

Represents a parameter to an OdbcCommand and optionally, its mapping to a DataColumn. This class cannot be inherited.

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

System.Object
  System.MarshalByRefObject
    System.Data.Common.DbParameter
      System.Data.Odbc.OdbcParameter

Public NotInheritable Class OdbcParameter
	Inherits DbParameter
	Implements ICloneable, IDbDataParameter, IDataParameter

NameDescription
System_CAPS_pubmethodOdbcParameter()

Initializes a new instance of the OdbcParameter class.

System_CAPS_pubmethodOdbcParameter(String, Object)

Initializes a new instance of the OdbcParameter class that uses the parameter name and an OdbcParameter object.

System_CAPS_pubmethodOdbcParameter(String, OdbcType)

Initializes a new instance of the OdbcParameter class that uses the parameter name and data type.

System_CAPS_pubmethodOdbcParameter(String, OdbcType, Int32)

Initializes a new instance of the OdbcParameter class that uses the parameter name, data type, and length.

System_CAPS_pubmethodOdbcParameter(String, OdbcType, Int32, ParameterDirection, Boolean, Byte, Byte, String, DataRowVersion, Object)

Initializes a new instance of the OdbcParameter class that uses the parameter name, data type, length, source column name, parameter direction, numeric precision, and other properties.

System_CAPS_pubmethodOdbcParameter(String, OdbcType, Int32, ParameterDirection, Byte, Byte, String, DataRowVersion, Boolean, Object)

Initializes a new instance of the OdbcParameter class that uses the parameter name, data type, length, source column name, parameter direction, numeric precision, and other properties.

System_CAPS_pubmethodOdbcParameter(String, OdbcType, Int32, String)

Initializes a new instance of the OdbcParameter class that uses the parameter name, data type, length, and source column name.

NameDescription
System_CAPS_pubpropertyDbType

Gets or sets the DbType of the parameter.(Overrides DbParameter.DbType.)

System_CAPS_pubpropertyDirection

Gets 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.)

System_CAPS_pubpropertyIsNullable

Gets or sets a value that indicates whether the parameter accepts null values.(Overrides DbParameter.IsNullable.)

System_CAPS_pubpropertyOdbcType

Gets or sets the OdbcType of the parameter.

System_CAPS_pubpropertyParameterName

Gets or sets the name of the OdbcParameter.(Overrides DbParameter.ParameterName.)

System_CAPS_pubpropertyPrecision

Gets or sets the number of digits used to represent the Value property.

System_CAPS_pubpropertyScale

Gets or sets the number of decimal places to which Value is resolved.

System_CAPS_pubpropertySize

Gets or sets the maximum size of the data within the column.(Overrides DbParameter.Size.)

System_CAPS_pubpropertySourceColumn

Gets or sets the name of the source column mapped to the DataSet and used for loading or returning the Value.(Overrides DbParameter.SourceColumn.)

System_CAPS_pubpropertySourceColumnNullMapping

Sets or gets a value which indicates whether the source column is nullable. This lets DbCommandBuilder correctly generate Update statements for nullable columns.(Overrides DbParameter.SourceColumnNullMapping.)

System_CAPS_pubpropertySourceVersion

Gets or sets the DataRowVersion to use when you load Value.(Overrides DbParameter.SourceVersion.)

System_CAPS_pubpropertyValue

Gets or sets the value of the parameter.(Overrides DbParameter.Value.)

NameDescription
System_CAPS_pubmethodCreateObjRef(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.)

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodInitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodResetDbType()

Resets the type associated with this OdbcParameter.(Overrides DbParameter.ResetDbType().)

System_CAPS_pubmethodResetOdbcType()

Resets the type associated with this OdbcParameter.

System_CAPS_pubmethodToString()

Gets a string that contains the ParameterName.(Overrides Object.ToString().)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodICloneable.Clone()

For a description of this member, see ICloneable.Clone.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDbDataParameter.Precision

Indicates the precision of numeric parameters.(Inherited from DbParameter.)

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIDbDataParameter.Scale

For a description of this member, see IDbDataParameter.Scale.(Inherited from DbParameter.)

Parameter names are not case sensitive.

When querying an Oracle database using the Microsoft OLE DB Provider for Oracle (MSDAORA) and the ODBC .NET Framework Data Provider, using the LIKE clause to query values in fixed-length fields might 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 will 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 OdbcParameter through the OdbcParameterCollection within the OdbcDataAdapter. 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 OdbcDataAdapter 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 OdbcConnection(connectionString)
        Dim adapter As New OdbcDataAdapter(queryString, connection)

        ' Set the parameters.
        adapter.SelectCommand.Parameters.Add( _
            "@CategoryName", OdbcType.VarChar, 80).Value = "toasters"
        adapter.SelectCommand.Parameters.Add( _
         "@SerialNum", OdbcType.Int).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
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft