Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

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...

C#
row1 = dsDetail.Tables["table"].NewRow();

dsDetail.Tables["table"].Columns["logo"].DataType=System.Type.GetType("System.Byte[]");
 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));

            fs.Close();

            return picbyte;
        }
Posted

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.
 
Share this answer
 
Yes, you can. please follow this code:

C#
DataTable dt = new DataTable();
            dt.Columns.Add("imageByte", typeof(byte[]));

            byte[] imageByte = null;
            imageByte=ImageToByteArray(Server.MapPath(@"\images\yourImage.png"));

            DataRow drNew = dt.NewRow();
            drNew["imageByte"] = imageByte;

            dt.Rows.Add(drNew);


thanks
Rashed::Bangladesh
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900