title: Image Load from SQL Server 2008 to PictureBox fails
body: <p>I am having trouble to read an image from a SQL Server 2008 database and load it in Windows Forms <code>PictureBox</code>. This is the code to retrieve image from DB:</p>
  
  <pre><code>//UI Button Binded Code
  private void LoadImage_Click(object sender, RoutedEventArgs e)
  {
     DataSet data = DBClient.GetEmployee(_EID[0]);
     //...
     //...
     byte[] pic = (byte[])data.Tables[0].Rows[0]["Picture"];
  
     EmployeeCardForm ef = new EmployeeCardForm(name, fname, nic, deptt, desig, doj, address, ecode, pic);
     ef.Show();
  }
  
   //EmployeeCardForm Constructor File Code
   public EmployeeCardForm(String name, String fname, String nic, String deptt, String desig, String doj, String address, String ecode, byte[] pic)
   {
          InitializeComponent();
          this.MaximizeBox = false;
          label18.Text = "Record has been successfully Saved. Please take Print out by pressing Print Button below!";
          try
          {
              pictureBox1.Image = Image.FromStream(new MemoryStream(pic));
              //Some code here
          }
          catch (IOException e)
          {
              MessageBox.Show("Some Error occurred!");
          }
          //declare event handler for printing in constructor
          printdoc1.PrintPage += new PrintPageEventHandler(printdoc1_PrintPage);
      }
  </code></pre>
  
  <p>When I run this program and click on the button to load image the application became unresponsive. After debugging I came to know that the following line of code has problem:</p>
  
  <pre><code>pictureBox1.Image = Image.FromStream(new MemoryStream(pic));
  </code></pre>
  
  <p><br/>
  And when I used try/catch block, it showed me following exception:<br/>
  <code>System.ArgumentException: Parameter is not valid. at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData) at System.Drawing.Image.FromStream(Stream stream) at SimpleReport.EmployeeCardForm..ctor(String name, String fname, String nic, String deptt, String desig, String doj, String address, String ecode, Byte[] pic) in D:\O Projects\EM\SimpleReport\EmployeeCardForm.cs:line 60</code>
  <br/><br/>
  This is how i am saving image into DB:</p>
  
  <pre><code>private void SaveImage_Click(object sender, RoutedEventArgs e)
  {
       Picture_Path= filename;
       FileStream fs;
       fs = new FileStream(@Picture_Path, FileMode.Open, FileAccess.Read);
       //a byte array to read the image
       byte[] picbyte = new byte[fs.Length];
       fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
       fs.Close();
       DBClient.AddEmployee(ecode, emp_name.Text, fname, nic, deptt, desig, doj, address, picbyte);
  }
  </code></pre>
  
  <p><br/>Please help me out!</p>