Database Column Type Codes

The following code may be used to derive details about the name, value and type for each column in the current row of a database table.

<%
Dim objFields As ADODB.Fields
Dim i As Integer

objRs.Open strSQL, strConnStr, adOpenForwardOnly, adLockReadOnly, adCmdText

Set objFields = objRS.Fields

For Each fieldF in objRS.Fields
  fieldName = fieldF.Name
  fieldType = fieldF.Type
  fieldValue = fieldF.Value
Next
%>

Where objRS is the database SQL statement and this piece of code is wrapped in a do while loop.

The information returned relating to the field type is not in an easily understood form. Given below is a table of field types with their corresponding returned integer value.

ValueColumn Type
0Empty
2SmallInt
3Integer
4Single
5Double
6Currency
7Date
8BSTR
9IDispatch
10Error
11Boolean
12Variant
13IUnknown
14Decimal
16TinyInt
17UnsignedTinyInt
18UnsignedSmallInt
19UnsignedInt
20BigInt
21UnsignedBigInt
64FileTime
72GUID
128Binary
129Char
130WChar
131WChar Numeric
132UserDefined
133DBDate
134DBTime
135DBTimeStamp
136Chapter
138PropVariant
139VarNumeric
200VarChar
201LongVarChar
202VarWChar
203LongVarWChar
204VarBinary
205LongVarBinary
&H2000Array