Marvin kakuru

Marvin kakuru

  • 1.4k
  • 355
  • 159.9k

view image in picturebox

Mar 22 2012 10:41 AM
 

Hi everyone,

 I am trying to select data including data that is saved as an image in my sql database, and view the image in a picturebox, below is the code I am using but it is retrieving  NO image in the picturebox

{

            SqlConnection cn = new SqlConnection("Data Source=KATOTO-PC;Initial Catalog =AssetRegister;User ID=sa;Password=Kyozi");

            string sql = ("select serialnumber,supplier,assetimage from AssetInformation where serialnumber like '" + textBox1.Text + "'");

 

            SqlCommand cmd = new SqlCommand(sql, cn);

            cn.Open();

 

            SqlDataReader sdr = cmd.ExecuteReader();

            sdr.Read(); // read first row

            textBox2.Text = sdr[2].ToString(); // read first column

 

          if (sdr.HasRows)

            {

               while (sdr.Read())

                {

 

                   byte[] getimage = (byte[])sdr[2];

                   MemoryStream ms = new MemoryStream(getimage);

                Image myimage = Image.FromStream(ms);

                   pictureBox2.Image = new System.Drawing.Bitmap(ms);

 

                   

 

 

                }

               sdr.Close();

             

            }

           

                      

        }

 

Please any help will greatly appreciated because I had this trouble for quite a while now.

Best regards.

 

 


Answers (8)