Reading Binary(16) field problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RoddyPiper
    New Member
    • Apr 2009
    • 2

    Reading Binary(16) field problem

    I am working with a sql server database. Due to a database udgrade, sever fields which were integer are now binary(16). These fields are used for joins later in the VB project. The problem I am haveing is that I have no idea how to read in the binary field! Here is the original code(using Visual Studio 08):

    strRptPars(iCou nt).lID = adoOleDbDataRea der.GetInt32(i)

    Originally strRptPars(iCou nt).lID was defined as LONG. I tried changing it to STRING, and using adoOleDbDataRea der.GetString(i). However, instead of getting the string rep of the binary field, I am getting the literal 'S' for read. Not sure what I am doing wrong - if anyone can help or direct me to a more appropriate forum for this you have my thanks!
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    binary 16 representation of an int would look like this

    0x000000001
    0x000000002

    the easiest solution is to cast this in your sql if you want an integer

    select cast(column as int) as whatever from table


    this would give you the integer you are looking for.. however why do you want an integer column to be binary 16 in the first place why not convert these back to integers?

    Comment

    • RoddyPiper
      New Member
      • Apr 2009
      • 2

      #3
      Hello - the original field in the database was integer, but was converted to binary(16). At any rate, I am able to read it now with the .GetBytes method, but I never though of doing a cast - something to remember in the future. I'm updating someone else's code and it is a real nightmare. If I had to do it over again I would have told the client that I am rewriting the damn thing from scratch. Thanks for your suggestion.

      Comment

      Working...