Summary

Represents the data types of fields in an ODBC data source.

The OdbcType enumeration is used by the System.Data.Odbc classes to specify the native data type of a parameter or a column.

Syntax

public enum OdbcType

Remarks

When you set a parameter's OdbcType property, the corresponding value is converted to the ODBC C data type. For a list of supported ODBC C data types, see the ODBC SDK documentation.

The OdbcType enumeration provides a mapping between .NET data types and ODBC C data types. This allows for consistent handling of data across different ODBC drivers.

Members

Member Description
BigInt A signed 8-byte integer.
Binary A binary number.
Bit A single bit value.
Char A single character.
Date A date.
DateTime A date and time value.
Decimal A fixed precision and scale numeric value.
Double A floating-point number.
Image Binary large object (BLOB).
Int A signed 4-byte integer.
NChar A fixed-length Unicode character string.
NText Unicode text data.
Numeric A fixed precision and scale numeric value.
NVarchar A variable-length Unicode character string.
Real A single-precision floating-point number.
SmallInt A signed 2-byte integer.
Text Text data.
Time A time value.
Timestamp A data type that is unique within a table.
TinyInt A signed 1-byte integer.
UniqueNChar A fixed-length Unicode character string.
UniqueNVarchar A variable-length Unicode character string.
UniqueVarChar A variable-length character string.
VarBinary A variable-length binary number.
Varchar A variable-length character string.
Variant A variant data type.
XML XML data.
Guid A globally unique identifier (GUID).
String A string data type.
StringFixed A fixed-length string data type.
Udt User-defined type.
Structured Structured data.
Array An array data type.
RowId Row identifier.

Example

The following example demonstrates how to use the OdbcType enumeration to specify the data type of an OdbcParameter.

using System;
using System.Data;
using System.Data.Odbc;

public class Example
{
    public static void Main(string[] args)
    {
        string connectionString = "DSN=MyDataSource;Uid=myuser;Pwd=mypassword;";
        using (OdbcConnection connection = new OdbcConnection(connectionString))
        {
            connection.Open();

            string query = "INSERT INTO MyTable (ID, Name, Salary) VALUES (?, ?, ?)";
            using (OdbcCommand command = new OdbcCommand(query, connection))
            {
                // Add parameters with specified OdbcType
                command.Parameters.Add("ID", OdbcType.Int).Value = 123;
                command.Parameters.Add("Name", OdbcType.NVarChar, 50).Value = "Alice";
                command.Parameters.Add("Salary", OdbcType.Decimal).Value = 50000.50m;

                command.ExecuteNonQuery();
            }
        }
    }
}