Click here to Skip to main content
Rate this: bad
good
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
0 Sergey Alexandrovich Kryukov 418
1 OriginalGriff 344
2 George Jonsson 233
3 Shemeemsha RA 138
4 Animesh Datta 130
0 OriginalGriff 6,179
1 Sergey Alexandrovich Kryukov 5,616
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 18 Dec 2012
Copyright © CodeProject, 1999-2014
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