Click here to Skip to main content
13,054,615 members (57,752 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I want to assign a byte array to datarow column...When i assigned like following the value is showing as "System.Byte[]" instead of actual byte array...

row1 = dsDetail.Tables["table"].NewRow();
 byte[] P = ImageToByteArray(a);
 row1["logo"] = P;

//function used to get byte array
  public byte[] ImageToByteArray(string imagepath)
            FileStream fs;
            fs = new FileStream(imagepath, FileMode.Open, FileAccess.Read);
            //a byte array to read the image
            byte[] picbyte = new byte[fs.Length];
            fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
            return picbyte;
Posted 18-Dec-12 4:43am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Yes, you can. please follow this code:

DataTable dt = new DataTable();
            dt.Columns.Add("imageByte", typeof(byte[]));
            byte[] imageByte = null;
            DataRow drNew = dt.NewRow();
            drNew["imageByte"] = imageByte;

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

When you assign a class to a column, and try to display it, the ToString method is called - if this is not overridden, then the default object.ToString method is executed. This prints the name of the class (as it has to do something) rather than the contents (since it may not know how to organise the content in a human readable way.

If you want to display the array content, then you need to create your own class which holds an array and override ToString yourself.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100