how to convert BLOB DB field to readable format (text)

S

Serge Klokov

Hello!

I have a Oracle table with a BLOB field.
Each field is actually a simple text file of several lines.
How to get this BLOB fields in readable format?

I tryied something like
row["DOCLIST"].ToString()

But it give result "System.Byte" instead of actual text...

Thank you,
 
W

Wiktor Zychla

I have a Oracle table with a BLOB field.
Each field is actually a simple text file of several lines.
How to get this BLOB fields in readable format?

I tryied something like
row["DOCLIST"].ToString()

But it give result "System.Byte" instead of actual text...

look at the GetString(...) method in the Encoding class. this will work for
you.

Regards,
Wiktor Zychla
 
S

Serge Klokov

It doesn't work, or i'm doing something wrong: Cannot implicitly convert
type 'object' to 'byte[]'

againg: I have record: row["DOCLIST"]

If i would save this record from Oracle to disc i will have plaint text
file:

one
two
three


in C#
String typ = row["DOCLIST"].GetType().ToString(); //return System.Byte[]

but all this doesn't work:
System.Byte[] sb = row["DOCLIST"]; //Error: Cannot implicitly convert type
'object' to 'byte[]'
String s = System.Text.Encoding.UTF8.GetString((row["DOCLIST"])); //Error:
Cannot implicitly convert type 'object' to 'byte[]'
String s2 =
System.Text.Encoding.UTF8.GetString(row["PACKAGENAME"].ToString()); //Error:
Cannot implicitly convert type 'object' to 'byte[]'


I have a Oracle table with a BLOB field.
Each field is actually a simple text file of several lines.
How to get this BLOB fields in readable format?

I tryied something like
row["DOCLIST"].ToString()

But it give result "System.Byte" instead of actual text...

look at the GetString(...) method in the Encoding class. this will work
for
 
S

Serge Klokov

This is working:

Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])(row["DOCLIST"]);
String s = System.Text.Encoding.UTF8.GetString(byteBLOBData);

Tnx for your help.
 
W

Wiktor Zychla

Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])(row["DOCLIST"]);
String s = System.Text.Encoding.UTF8.GetString(byteBLOBData);

then this should work also:

byte[] byteBLOBData = (Byte[])(row["DOCLIST"]);
String s = System.Text.Encoding.UTF8.GetString(byteBLOBData);
 

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