title: Extract Image from MSAccess OLE object using C#.NET
body: <p>We have a legacy system in MSAccess which has a "OLE Object" Column to store images.
  Now, we are trying to create a small executable to convert the "OLE object" back to image file using C#.
  We came to know the users takes screenshot and paste dierctly to the MSAccess column.</p>
  
  <p>But while retrieving data from access it returns the bytes but throws  <strong>'Parameter is not valid.'</strong> exception
  while doing Image.FromStream(ms).</p>
  
  <p>Here is my sample code.</p>
  
  <pre><code>//Connect to MSAccess database
  using (OleDbConnection conn = new OleDbConnection(connectionString))
  {
  try
  {
    DataTable dt = new DataTable();
    using (OleDbCommand cmd = new OleDbCommand(commandText, conn))
    {
      using (OleDbDataAdapter da = new OleDbDataAdapter(cmd))
      {
        da.Fill(dt);
        if (dt != null &amp;&amp; dt.Rows.Count &gt; 0)
        {
                                  foreach (DataRow dr in dt.Rows)
                                  {
                                      Byte[] imageBytes = dr[0] as Byte[];                                    
                                      MemoryStream ms = new MemoryStream(imageBytes);
                                      Image img = Image.FromStream(ms);
                                      img.Save(destinationPath + "Image1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);                                    
                                  }
                              }
                          }
                      }
                  }
         finally
         {
           conn.Close();
         }
  } 
  </code></pre>
  
  <p>Any help is highly appreciated.</p>