473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

casting BLOB to a string

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
Nov 18 '05 #1
2 6539
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.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"martin" <ma***************@hotmail.com> wrote in message
news:Og**************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #2
Chris Jackson wrote:
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.

--
mikeb
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: pb | last post by:
Hi, I'm having problems deploying a project to win2003. It is currently on win2000 server and works fine - it also works fine on my development machine - win2003. Both my machine and the new...
1
by: sid_mulpuru | last post by:
I am trying to read data from a DB2 Blob Data type Field (using wsad 5.1.0) using getBlob() which when executed gives an SQL Exception 2005-01-07 15:48:40,506 ERROR - Error in...
1
by: Markus | last post by:
This is my TABLE: CREATE TABLE test( data BLOB ) This is my INSERT: INSERT INTO test(data) VALUES (CAST('I am a test' AS BLOB)) But how can I SELECT the data as VARCHAR, so that I can see...
11
by: Chris Fink | last post by:
I have setup an Oracle table which contains a blob field. How do I insert data into this field using C# and ADO.net?
0
by: martin | last post by:
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...
1
by: Markusek Peter | last post by:
Hi, I'm using MySQLDriverCS. I've got no problem to store BLOB into database, but I can't get it back(save to file). Problem is with DataTable(returns string:( ) My code: -- DataTable dt = new...
6
by: Selen | last post by:
I would like to be able to extract a BLOB from the database (SqlServer) and pass it to a browser without writing it to a file. (The BLOB's are word doc's, MS project doc's, and Excel spreadsheets....
0
by: Biztalk Migration | last post by:
I am new to using BLOB with oracle stored proc. I dont knw how to set the size of the buffer which seems to overflow no matter what i used to pass it. I am getting an error ...
29
by: Tony Johansson | last post by:
Hello! Here I have two different way to use casting. Is any of these any better then the other? Or is it just a question of taste. newCards.Add((Card)sourceCard.Clone());...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.