473,403 Members | 2,293 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,403 software developers and data experts.

Converting object to byte array

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
Nov 15 '05 #1
4 3860
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" <an*******@discussions.microsoft.com> wrote in message
news:75**********************************@microsof t.com...
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

Nov 15 '05 #2
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" <an*******@discussions.microsoft.com> wrote in message
news:75**********************************@microsof t.com...
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

Nov 15 '05 #3
I tried this approach first and it did not go through either. It resulted with the same exception
Svetoslav
Nov 15 '05 #4
I tried this approach first and it did not go through either. It resulted with the same exception
Svetoslav
Nov 15 '05 #5

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

Similar topics

5
by: matt melton | last post by:
Hi there, I am trying to write a method that accepts an array of any primitive type and will return the same array without copying memory as an array of bytes. ie. I'd like to be able to do...
2
by: Govind | last post by:
Hi All, I want to Convert 32 bit integers to byte in right alighed format . For 32 = the usual way is BitConverter.GetBytes(int32)==> xx xx 00 00 , but i want right aligned like 00 00 xx xx.Is...
4
by: Joseph Suprenant | last post by:
I have an array of unsigned chars and i would like them converted to an array of ints. What is the best way to do this? Using RedHat 7.3 on an Intel Pentium 4 machine. Having trouble here, hope...
5
by: Mark Rae | last post by:
Hi, Can anyone please tell me how to convert an object say, a System.Web.Mail.MailMessage object, to a byte array and then convert the byte array to a Base64 string? Any assistance gratefully...
8
by: iyuen | last post by:
I'm having problems with converting a byte array to an image object~ My byte array is an picture in VB6 StdPicture format. I've used propertybag to convert the picture into base64Array format in...
2
by: Matt | last post by:
I just wanted to know if I am converting to/from streams the easiest and correct way. I am performing the following statements to convert byte arrays to and from streams during different...
8
by: moondaddy | last post by:
I need to convert a byte array to a string and pass it as a parameter in a URL and then convert it back to the original byte array. However, its getting scrambled in the conversion. In short,...
5
by: Lint Radley | last post by:
Hello, I am looking for a way to cast a byte to Int16. I get this error: "Unable to cast object of type 'System.Byte' to type 'System.Int16'" If you're curious, I am using a library for...
2
by: shahiz | last post by:
basically im having null pointer exception //read an inputstream is = new DataInputStream(new FileInputStream("test.mpg")); loadBytes(is); //pass it as a datasource for the player public...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.