C# .NET - I want to display image on smart device emulator from database using c#.

Asked By Narendra on 24-Sep-12 05:27 AM
Hi All,

I want to use an image on smart device using c# from database (binary image).

Currently I am using
        byte[] bytearray = clsPatient.PatientImage;
        System.IO.MemoryStream memStream = new System.IO.MemoryStream(bytearray , true);
          memStream.Write(bytearray , 0, bytearray .Length);
          System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(memStream);
          PatientImage.Image = bmp;

    but it give an exception (Value does not fall within the expected range) on last line.

Thanks in advance
Narendra Singh
Jitendra Faye replied to Narendra on 25-Sep-12 12:21 AM
Try this code-

SqlConnection cn = new SqlConnection("con string");
            string strQuery = "Select * from EmpImage";
            SqlDataAdapter da = new SqlDataAdapter(strQuery, cn);
            DataSet ds = new DataSet();

            byte[] b = new byte[0];
            b = (Byte[])(ds.Tables[0].Rows[0][1]);

            MemoryStream ms = new MemoryStream(b);

             pictureBox1.Image = Image.FromStream(ms);

and let me know.