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

LVL 1
techsuppoprtAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

techsuppoprtAuthor Commented:
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 ?
0
Meir RivkinFull stack Software EngineerCommented:
try converting to string this way:

System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string str = enc.GetString(bytes);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.