casting BLOB to a string

M

martin

Hi,

I have blob field in my database.
I am retrieveing the field through a stored procedure and the execute scalar
method.

I would like to cast resulting "byte" field to a string.
I am using the syntax
 
C

Chris Jackson

It's not as simple as a cast. You will get a byte[] from the database, and
you can create a new MemoryStream and then pull data from that MemoryStream,
using tools such as the BinaryFormatter to serialize and deserialize from
that stream.
 
M

mikeb

Chris said:
It's not as simple as a cast. You will get a byte[] from the database, and
you can create a new MemoryStream and then pull data from that MemoryStream,
using tools such as the BinaryFormatter to serialize and deserialize from
that stream.

Or if the byte array blob is truly just a string of characters something
like:

string s = System.Text.Encoding.Unicode.GetString( blob);

would do the trick - changing the encoding from Unicode to whatever is
appropriate if the blob is not Unicode characters.
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top