Type 属性范例

该范例通过显示与雇员表所有 Field 对象的 Type 属性值对应的常量名说明 Type 属性。该过程运行时需要 FieldType 函数。

Public Sub TypeX()   Dim rstEmployees As ADODB.Recordset
   Dim fldLoop As ADODB.Field
   Dim strCnn As String   ' 使用雇员表中的数据打开记录集。
   strCnn = "Provider=sqloledb;" & _
      "Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
   Set rstEmployees = New ADODB.Recordset
   rstEmployees.Open "employee", strCnn, , , adCmdTable   Debug.Print "Fields in Employee Table:" & vbCr   ' 枚举雇员表的字段集合。
   For Each fldLoop In rstEmployees.Fields
      Debug.Print "  Name: " & fldLoop.Name & vbCr & _
         "  Type: " & FieldType(fldLoop.Type) & vbCr
   Next fldLoopEnd SubPublic Function FieldType(intType As Integer) As String   Select Case intType
      Case adChar
         FieldType = "adChar"
      Case adVarChar
         FieldType = "adVarChar"
      Case adSmallInt
         FieldType = "adSmallInt"
      Case adUnsignedTinyInt
         FieldType = "adUnsignedTinyInt"
      Case adDBTimeStamp
         FieldType = "adDBTimeStamp"
   End SelectEnd Function
www.holmesian.org