PC Review


Reply
Thread Tools Rate Thread

convert binary(20) to string

 
 
SM
Guest
Posts: n/a
 
      20th Feb 2007
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      20th Feb 2007
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" wrote:

> 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
>
>
>

 
Reply With Quote
 
SM
Guest
Posts: n/a
 
      21st Feb 2007
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 [C# MVP]" <(E-Mail Removed)> wrote in
message news:2AF21AA0-8C03-46C0-AA92-(E-Mail Removed)...
> 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" wrote:
>
>> 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
>>
>>
>>



 
Reply With Quote
 
Mythran
Guest
Posts: n/a
 
      21st Feb 2007


"SM" <(E-Mail Removed)> wrote in message
news:##(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert string to binary =?Utf-8?B?YmJkb2J1ZGR5?= Microsoft C# .NET 5 5th Apr 2007 06:07 PM
convert from string to binary =?Utf-8?B?YmJkb2J1ZGR5?= Microsoft C# .NET 1 5th Apr 2007 05:40 PM
convert a string to a binary Sam Microsoft VB .NET 4 3rd Jun 2005 09:22 AM
Re: How to convert string to binary Jon Skeet [C# MVP] Microsoft C# .NET 0 4th Aug 2004 01:02 PM
HOWTO Convert Byte or int to Binary String in C#? =?Utf-8?B?Q1NoYXJwZW5lcg==?= Microsoft C# .NET 4 2nd Apr 2004 11:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:38 AM.