INF: Interpreting BINARY Data w/ Visual Basic Library for SQL

Last reviewed: April 28, 1997
Article ID: Q94181

The information in this article applies to:

  - Microsoft SQL Server Programmer's Toolkit, version 4.2

SUMMARY

Special handling is necessary when using the Visual Basic Library for SQL in order to form an ASCII representation of BINARY or VARBINARY data retrieved from SQL Server. The SQLData$ function returns character string representations of most datatypes; however, BINARY, VARBINARY, and IMAGE data are returned as strings of binary data. That is, the string returned from SQLData$ represents the actual data stored in SQL Server.

Character string representation of BINARY data might be necessary in applications making use of TIMESTAMP data (represented by VARBINARY(8) within SQL Server) when evaluating SQL Server global variables such as @@DBTS, or when implementing a robust ad-hoc query processor.

MORE INFORMATION

The code fragment below describes how to incorporate processing within a SQL results handler in order to form an ASCII representation of BINARY data. The PadLeft$() function is necessary to ensure that each hexadecimal number is translated into a two-character ASCII representation.

' code fragment for processing binary data

    coltype% = SQLColType%(sqlconn%, X%)
    colvalue$ = SqlData(sqlconn%, X%)
   ' coltype 45 = BINARY DATA
    If coltype% = 45 Then
        buffer$ = "0x"
        For yy = 1 To Len(colvalue$)
    buffer$ = buffer$ + PadLeft$(Hex$(Asc(Mid$(colvalue$, yy, 1))), 2, "0")
         Next yy
         colvalue$ = buffer$
    End If

' zero padding function

Function PadLeft$ (ByVal ST$, ByVal NUM%, ByVal padchar$)
    ST$ = Trim(ST)
    PD$ = ""

    If (Len(ST) < NUM) Then
        For X = 1 To NUM - Len(ST)
            PD$ = PD$ + padchar$
        Next X
    End If

    PadLeft$ = PD$ + ST$

End Function


Additional query words: vb
Keywords : kbinterop SSrvProg SSrvVisB
Version : 4.2 | 4.2
Platform : MS-DOS WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.