retreiving image(var binary in sql) from sql to picturebox RRS feed

  • Question

  • hi guys i dont know what is the problem with the code below that the byte[] takes value "0".?what should i write?

    Code Snippet

    System.Data.SqlClient.SqlConnection connect = new System.Data.SqlClient.SqlConnection("Server=.;Database=RegistrationSystem;integrated security=true"); System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("select fldPicture from tblPersonels", connect); connect.Open(); 

    byte[] obj = (byte[])command.ExecuteScalar(); 

    MemoryStream stream=new MemoryStream(); 


    Image image = Image.FromStream(stream); 

    pictureBox1.Image = image;

    Saturday, May 10, 2008 8:27 AM

All replies

  • Check whether the image is null or lenth==0.
    Saturday, May 10, 2008 8:48 AM
  • could you write one example .showing me how to bring image from swl to picturebox
    Saturday, May 10, 2008 8:58 AM
  • You haven't rewound the stream - it is still at the end. Either set Position to 0, or (more simply) use:

    MemoryStream stream = new MemoryStream(obj);

    (where "obj" is your existing byte[] buffer).



    Saturday, May 10, 2008 9:12 AM
  • i have done that but it doesn't work.please help me
    Saturday, May 10, 2008 9:20 AM
  • Are you sure you actually have any data in "obj"? What is the length of the stream?


    For info - here's some examples of working with larger streams - not sure they'll help initially, though.




    Saturday, May 10, 2008 10:09 AM