This documentation is archived and is not being maintained.

OdbcParameter.DbType Property

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Gets or sets the DbType of the parameter.

[Visual Basic]
Public Overridable Property DbType As DbType  Implements _
   IDataParameter.DbType
[C#]
public virtual DbType DbType {get; set;}
[C++]
public: __property virtual DbType get_DbType();
public: __property virtual void set_DbType(DbType);
[JScript]
public function get DbType() : DbType;
public function set DbType(DbType);

Property Value

One of the DbType values. The default is String.

Implements

IDataParameter.DbType

Exceptions

Exception Type Condition
ArgumentOutOfRangeException The property was not set to a valid DbType.

Remarks

The OdbcType and DbType are linked. Therefore, setting the DbType changes the OdbcType to a supporting OdbcType.

For a list of the supported data types, see the appropriate OdbcType member. For more information, see Using Parameters with a DataAdapter.

Note    Object is not supported by the .NET Framework Data Provider for ODBC.

Example

[Visual Basic, C#, C++] The following example creates an OdbcParameter and sets some of its properties, including the DbType Property.

[Visual Basic] 
Public Sub CreateMyProc(myConnection As OdbcConnection)

    Dim myCommand As OdbcCommand = myConnection.CreateCommand()
    myCommand.CommandText = { call MyProc(?,?,?) }

    myCommand.Parameters.Add("", OdbcType.Int).Value = 1
    myCommand.Parameters.Add("", OdbcType.Decimal).Value = 2
    myCommand.Parameters.Add("", OdbcType.Decimal).Value = 3

End Sub ' CreateMyProc

[C#] 
public void CreateMyProc(OdbcConnection myConnection) 
{
    OdbcCommand myCommand = myConnection.CreateCommand();
    myCommand.CommandText = "{ call MyProc(?,?,?) }";

    myCommand.Parameters.Add("", OdbcType.Int).Value = 1;
    myCommand.Parameters.Add("", OdbcType.Decimal).Value = 2;
    myCommand.Parameters.Add("", OdbcType.Decimal).Value = 3;
}

[C++] 
public:
void CreateMyProc(OdbcConnection* myConnection) 
{
    OdbcCommand* myCommand = myConnection->CreateCommand();
    myCommand->CommandText = S"{ call MyProc(?,?,?) }";

    myCommand->Parameters->Add(S"", OdbcType::Int)->Value = __box(1);
    myCommand->Parameters->Add(S"", OdbcType::Decimal)->Value = __box(2);
    myCommand->Parameters->Add(S"", OdbcType::Decimal)->Value = __box(3);
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

OdbcParameter Class | OdbcParameter Members | System.Data.Odbc Namespace | OdbcType

Show: