該范例使用 NumericScale 和 Precision 屬性來顯示在 Pubs 數(shù)據(jù)庫 Discounts 表中字段的數(shù)值范圍和精度。
Public Sub NumericScaleX()
Dim rstDiscounts As ADODB.Recordset
Dim fldTemp As ADODB.Field
Dim strCnn As String
' 打開記錄集。
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
Set rstDiscounts = New ADODB.Recordset
rstDiscounts.Open "discounts", strCnn, , , adCmdTable
' 顯示數(shù)字和小整數(shù)字段的數(shù)值范圍和精度。
For Each fldTemp In rstDiscounts.Fields
If fldTemp.Type = adNumeric _
Or fldTemp.Type = adSmallInt Then
MsgBox "Field: " & fldTemp.Name & vbCr & _
"Numeric scale: " & _
fldTemp.NumericScale & vbCr & _
"Precision: " & fldTemp.Precision
End If
Next fldTemp
rstDiscounts.Close
End Sub