tags:

views:

938

answers:

2

I have an image data type in my table. When I query using SQL Server Management Studio, I get the following in my results window, both grid and text.

0x255044462D312E320D0A0D0A332030206F[Truncated for Length]

I am attempting to replicate this in a little c# program.

However, when I use either SqlCommand or LINQ I get the output: JVBERi0xLjINCg0KMyAwIG9iag0KPDwNCi9FIDIxODgyDQovSCBbIDExNTAgMTUxIF0NCi9MIDIyM[TRUNCATED]

Any thoughts to what I need to do to get the 0x25... output to display? I have tried doing byte[] conversions and Encoding, but can't seem to find the right one.

If I am not clear, please let me know.

Edit: I am not trying to display the image, just the 0x25...

Thoughts?

+1  A: 
SLaks
Thank you also for your response. this program will not go into production, so i don't have a worry for performance. I appreciate your responses!
Jason Heine
@SLaks: I just ran some quick tests, and the `StringBuilder` loop appears to be 2 or 3 times *slower* than the "incredibly inefficient" `BitConverter`/`Replace`.
LukeH
I cannot imagine why; I'll take a look.
SLaks
SLaks
@SLaks: Yep, the new version is faster! This is pretty much what `BitConverter.ToString` does behind-the-scenes, but obviously you skip adding the hyphens which means that you don't then need the `Replace` call to remove them afterwards.
LukeH
I know - I checked.
SLaks
+4  A: 
string forDisplay = "0x" + BitConverter.ToString(yourByteArray).Replace("-", "");
LukeH
Ahh, this did it. thank you so much
Jason Heine