Connecting Tech Pros Worldwide Forums | Help | Site Map

Reading Binary(16) field problem

Newbie
 
Join Date: Apr 2009
Posts: 2
#1: Apr 7 '09
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(iCount).lID = adoOleDbDataReader.GetInt32(i)

Originally strRptPars(iCount).lID was defined as LONG. I tried changing it to STRING, and using adoOleDbDataReader.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's Avatar
Forum Leader
 
Join Date: Jul 2006
Location: Oklahoma
Posts: 1,076
#2: Apr 14 '09

re: Reading Binary(16) field problem


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?
Newbie
 
Join Date: Apr 2009
Posts: 2
#3: Apr 18 '09

re: Reading Binary(16) field problem


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.
Reply


Similar Visual Basic .NET bytes