none
How to retrieve a Image from SQL Server 2008 and populate an ImageBox using C# on winForms? RRS feed

  • Question

  • Ok I'm using a Sproc to retrieve data from several tables from a database on SQL Server 2008, I'm successfull to retrieve the data but it seems that there is no possible converion between the image Linq-To-SQL gets from the databse and the Imagebox.
    I keep getting the following error: Cannot implicitly convert type 'System.Data.Linq.Binary' to 'System.Drawing.Image'

    I have looked at many sugestion on the web and all of them return another flavor of the same error.

    foreach (vw_all a in q)
                    {
                    Name_txtbx.Text = a.nome;
                    My_img.Image = a.scan_img;
                    }
    The a.scan_img is the actual image  and My_img is the name of the imagebox.

    Thanks,
    Al
    Saturday, August 22, 2009 9:54 PM

Answers

  • The problem is that a binary object is not an image object so you need to create an image and feed the binary into it.

    What image file format does the binary contain?

    If it was a bitmap, you could do something like:

    foreach (vw_all a in q)
                    {
                    Name_txtbx.Text = a.nome;
                    My_img.Image = new Bitmap(new MemoryStream(a.scan_img.ToArray()));
                    }

    [)amien
    • Marked as answer by Zhipeng Lee Friday, August 28, 2009 1:37 AM
    Monday, August 24, 2009 4:16 PM
    Moderator