convert binary(20) to string

S

SM

Hi,

I have a column with SQL Server type binary(20) (contain a sql handle, ex :
0x01000800B73B573B98C6B1030000000000000000)

I want to convert this column to string value with this code :

string sql_hndl = MyDataRow["ColWithBinaryType"].tostring;

I'm expecting '0x01000800B73B573B98C6B1030000000000000000' string value, but
I've got 'array[]' value

Is there any simple way to convert sql server binary type to string

Thank you for your help
 
G

Guest

The first question I would ask is, "what on earth do you expect to be able to
do with the string representation of a SQLHandle?".

You will probably need to do something like:

string s = System.Text.Encoding.UTF8.GetSTring( (byte[])
MyDataRow["ColWithBinaryType"] )

Peter
 
S

SM

Thank you
The conversion did not work, I need SQL Handle to capture query that block
other process :):fn_get_sql())
Never mind I've process all things in server side



Peter Bromberg said:
The first question I would ask is, "what on earth do you expect to be able
to
do with the string representation of a SQLHandle?".

You will probably need to do something like:

string s = System.Text.Encoding.UTF8.GetSTring( (byte[])
MyDataRow["ColWithBinaryType"] )

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




SM said:
Hi,

I have a column with SQL Server type binary(20) (contain a sql handle,
ex :
0x01000800B73B573B98C6B1030000000000000000)

I want to convert this column to string value with this code :

string sql_hndl = MyDataRow["ColWithBinaryType"].tostring;

I'm expecting '0x01000800B73B573B98C6B1030000000000000000' string value,
but
I've got 'array[]' value

Is there any simple way to convert sql server binary type to string

Thank you for your help
 
M

Mythran

SM said:
Hi,

I have a column with SQL Server type binary(20) (contain a sql handle, ex
:
0x01000800B73B573B98C6B1030000000000000000)

I want to convert this column to string value with this code :

string sql_hndl = MyDataRow["ColWithBinaryType"].tostring;

I'm expecting '0x01000800B73B573B98C6B1030000000000000000' string value,
but I've got 'array[]' value

Is there any simple way to convert sql server binary type to string

Thank you for your help

Quick sample:

byte[] bytes = dataRow.BinaryFieldHere;
StringBuilder sb = new StringBuilder();
foreach (byte b in bytes) {
sb = sb.Append(b.ToString("X").PadLeft(2, '0'));
}

if (sb.Length > 0) {
sb = sb.Insert(0, "0x");
}

string binaryString = sb.ToString();

HTH (untested),
Mythran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top