NumericScale and Precision Properties Example (VB)

Microsoft ActiveX Data Objects (ADO)

NumericScale and Precision Properties Example (VB)

This example uses the NumericScale and Precision properties to display the numeric scale and precision of fields in the Discounts table of the Pubs database.

Public Sub NumericScaleX()

    Dim rstDiscounts As ADODB.Recordset
    Dim fldTemp As ADODB.Field
    Dim strCnn As String

    ' Open recordset.
    strCnn = "Provider=sqloledb;" & _
        "Data Source=srv;Initial Catalog=Pubs;User Id=sa;Password=; "
    Set rstDiscounts = New ADODB.Recordset
    rstDiscounts.Open "Discounts", strCnn, , , adCmdTable

    ' Display numeric scale and precision of
    ' numeric and small integer fields.
    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