Export (0) Print
Expand All

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)

'Declaration
<TypeConverterAttribute(GetType(OdbcParameterConverter))> _
Public NotInheritable Class OdbcParameter
	Inherits DbParameter
	Implements ICloneable, IDbDataParameter, IDataParameter
'Usage
Dim instance As OdbcParameter

/** @attribute TypeConverterAttribute(System.Data.Odbc.OdbcParameter+OdbcParameterConverter) */ 
public final class OdbcParameter extends DbParameter implements ICloneable, IDbDataParameter, 
	IDataParameter
TypeConverterAttribute(System.Data.Odbc.OdbcParameter+OdbcParameterConverter) 
public final class OdbcParameter extends DbParameter implements ICloneable, IDbDataParameter, 
	IDataParameter
Not applicable.

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

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

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

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1

Community Additions

ADD
Show:
© 2014 Microsoft