Link to home
Start Free TrialLog in
Avatar of techsuppoprt
techsuppoprt

asked on

Failing to get and decode Binary value from Sybase [C#]

Hi Experts

I would really appreciate your help on this one. I need to get this done asap and it doesnt seem to work.
I have a Sybase DB field "Long Binary" type that I'm pulling values from and trying to "decode" them and turn into regular strings.

To do this I create a byte[] array, read values from that Sybase field with DataReader.GetBytes into that array and then simply loop through the array to build my final string.
Simple but for some reason 30% of the time or so GetBytes returns nothing. It doesn't turn pulled in database values into the Bytes[] array and it's driving me nuts.
Can't figure out what's going on. Please help.

Here is my code
byte[] bytes = new byte[size];

reader.GetBytes(fldID, 0, bytes, 0, bytes.Length); //This for some reason doesnt populate my bytes[] array sometimes
         
foreach (byte b in bytes)
{
result = !b.Equals(DBNull.Value) ? result + Convert.ToChar(b) : result + "\0";
}

Open in new window

Avatar of techsuppoprt
techsuppoprt

ASKER

So is there another way to pull the bytes[] array from my DataReader because GetBytes() doesn't seem to work properly for me this way.
Anyone ?
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial