none
how to retrieve an image (binary type) from SQL2008 and put it in a picture box using LINQ in c# RRS feed

  • Question

  • Hello

    i need to retrieve an image from SQL by LinQ to SQL, but i don't know how to get it.

    any body can help me...? Thank you

    Tuesday, September 20, 2011 4:23 AM

Answers

  • Hi,

    What about something like this:

    var product = from p in context.tblProducts
               where p.ProductId == 1
               select new
               {
                 Image = p.Image
               };
    
    pictureBox1.Image = Image.FromStream( new System.IO.MemoryStream( product.Single().Image.ToArray() ) );
    
    

    Best regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    • Marked as answer by Nazanin24 Thursday, September 22, 2011 6:49 AM
    Tuesday, September 20, 2011 7:58 AM

All replies

  • Hi,

    What about something like this:

    var product = from p in context.tblProducts
               where p.ProductId == 1
               select new
               {
                 Image = p.Image
               };
    
    pictureBox1.Image = Image.FromStream( new System.IO.MemoryStream( product.Single().Image.ToArray() ) );
    
    

    Best regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    • Marked as answer by Nazanin24 Thursday, September 22, 2011 6:49 AM
    Tuesday, September 20, 2011 7:58 AM
  • I really Thank you,it worked

     

    Thursday, September 22, 2011 6:54 AM