1

During display of an image from database in the gridview control, the following error occurred: Parameter is not valid

The following code displays the image:

        var id = Convert.ToString(user_id);

        var category = (from data in db.Register1_db
                        where (data.User_ID == id)
                       select ( data.Student_Photo));

        int len = category.First().Length;
        // Output the binary data          
        // But first we need to strip out the OLE header          
        int OleHeaderLength = 78;
        int strippedImageLength = len - OleHeaderLength;
        byte[] imagdata = new byte[strippedImageLength];          
        Array.Copy(category.First().ToArray(), OleHeaderLength, imagdata, 0, strippedImageLength);          
        if ((imagdata) != null)          
        {              
            MemoryStream m = new MemoryStream(imagdata);

                //error occurred               
            System.Drawing.Image image = System.Drawing.Image.FromStream(m);              
            image.Save(context.Response.OutputStream, ImageFormat.Jpeg);          
        }
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
adiyaman
  • 17
  • 1
  • 1
  • 3
  • How are you executing this code? This would work if its a handler, but not if it's defined in the page code behind. Also where in the code is this happening? – Brian Mains Oct 08 '12 at 01:07
  • 1
    This is one, of many reasons, why most developers store images outside the database. – Steve Wellens Oct 08 '12 at 01:09

1 Answers1

0

The better way to display image in a gridview is using Image handlers. Check this

Community
  • 1
  • 1
Vijaychandar
  • 716
  • 5
  • 21
  • Trying to get an answer to my issue here. I have two images which I want to display in a grid which displays students. One of the image will be displayed depending on whether a student is enrolled or not, This view I have is strongly typed, how can I get this to work? – user793468 Nov 08 '12 at 20:25