ADO 2.7 Samples

Type Property Example (Field) (VB)

This example demonstrates the Type property by displaying the name of the constant that corresponds to the value of the Type property of all the Field objects in the Employees table. The FieldType function is required for this procedure to run.

'BeginTypeFieldVB
Public Sub TypeX()

    'To integrate this code
    'replace the data source and initial catalog values
    'in the connection string
   
   Dim Cnxn As ADODB.Connection
   Dim rstEmployees As ADODB.Recordset
   Dim fld As ADODB.Field
   Dim strCnxn As String
   Dim strSQLEmployee As String
   Dim FieldType As String

   ' Open connection
   Set Cnxn = New ADODB.Connection
   strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=Pubs;User Id=sa;Password=; "
   Cnxn.Open strCnxn
    
   ' Open recordset with data from Employees table
   Set rstEmployees = New ADODB.Recordset
   strSQLEmployee = "employee"
   rstEmployees.Open strSQLEmployee, Cnxn, , , adCmdTable
   'rstEmployees.Open strSQLEmployee, Cnxn, adOpenStatic, adLockReadOnly, adCmdTable
    ' the above two lines of code are identical

   Debug.Print "Fields in Employees Table:" & vbCr

   ' Enumerate Fields collection of Employees table
   For Each fld In rstEmployees.fields
   
       ' translate field-type code to text
     Select Case fld.Type
       Case adChar
          FieldType = "adChar"
       Case adVarChar
          FieldType = "adVarChar"
       Case adSmallInt
          FieldType = "adSmallInt"
       Case adUnsignedTinyInt
          FieldType = "adUnsignedTinyInt"
       Case adDBTimeStamp
          FieldType = "adDBTimeStamp"
     End Select
       ' show results
     Debug.Print "  Name: " & fld.Name & vbCr & _
         "  Type: " & FieldType & vbCr
   
   Next fld

End Sub
'EndTypeFieldVB


Attribute VB_Name = "TypeField"

See Also

Field Object | Type Property

© 1998-2001 Microsoft Corporation. All rights reserved.