Click here to Skip to main content
12,394,769 members (67,336 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
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...

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 18-Dec-12 4:43am
Rate this: bad
 
good
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;
            imageByte=ImageToByteArray(Server.MapPath(@"\images\yourImage.png"));
 
            DataRow drNew = dt.NewRow();
            drNew["imageByte"] = imageByte;
 
            dt.Rows.Add(drNew);

thanks
Rashed::Bangladesh
  Permalink  
Rate this: bad
 
good
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.
  Permalink  

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.160721.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2016
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