views:

20

answers:

2

I want to add the value from my database to a label

the value has a datatype varbinary(max)

string buF = dt.Rows[i]["BuF"].ToString();
                Label3.Text = buF;

for this i get the output as System.Byte[] which is not the correct value..

any suggestions??

thanks

+1  A: 

This sounds like a job for the BitConverter class:

string buF = BitConverter.ToString((byte[])dt.Rows[i]["BuF"]);
Label3.Text = buF;

Note that this will insert hyphens between each byte value in the output string. If you want to remove the hyphens and/or generate a different string format then you could do something like this, for example:

string buF =
    "0x" + BitConverter.ToString((byte[])dt.Rows[i]["BuF"]).Replace("-", "");
Label3.Text = buF;
LukeH
A: 

Is the data some sort of text encoded as binary? Then use the appropiate Encoding GetString(). You must use the same encoding type (ASCII, UTF8, Unicode etc) or build one with the appropiate CodePage for whatever is in that binary field.

Remus Rusanu