Converting object to byte array

G

Guest

Hi, I experience some troubles trying to convert an object,returned by a DataTable for a field value to its actual representation of Byte[]. The field values in a DataTable as we all know are returned as instance of the Object class and it is up to the developer to cast it to its actual type.
In my case i access a field of type text in the database and obviously the driver converts it into byte array. Unfortunaletly a construct like this
Array arr = (Array)dt.Rows[0]["FieldName"
always results in a CastNotValidException
However the dt.Rows[0]["FieldName"].ToString() returns "System.Bute[]", which actually prompts for the actual type
Any hints on how to solve this problem appreciated
Thanks in advance
Svetoslav
 
J

Justin Rogers

byte[] fieldXXXValue = (byte[]) dt.Rows[0]["FieldXXXName"];

Thought I'm not sure why you can't cast it all the way down to an array.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers


Svetoslav Vasilev said:
Hi, I experience some troubles trying to convert an object,returned by a
DataTable for a field value to its actual representation of Byte[]. The field
values in a DataTable as we all know are returned as instance of the Object
class and it is up to the developer to cast it to its actual type.
In my case i access a field of type text in the database and obviously the
driver converts it into byte array. Unfortunaletly a construct like this:
Array arr = (Array)dt.Rows[0]["FieldName"]
always results in a CastNotValidException.
However the dt.Rows[0]["FieldName"].ToString() returns "System.Bute[]", which
actually prompts for the actual type.
 
G

Guest

I tried this approach first and it did not go through either. It resulted with the same exception
Svetoslav
 

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