shiju kv

shiju kv

  • NA
  • 91
  • 16.3k

storing image to database

Feb 12 2015 6:58 AM
i would like to store one image to databse. while inserting it shows an exception like
 
"Object reference not set to an instance of an object" in
 
 "pictureBox2.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)" this line
 
here is my code to insert 
 
MemoryStream ms = new MemoryStream();
pictureBox2.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] photo_aray = new byte[ms.Length];
ms.Position = 0;
ms.Read(photo_aray, 0, photo_aray.Length);
please help to find a solution
 
thanks 

Answers (1)