title: How to Display attachments image from access db in picturebox
body: <p>im trying to display image from database Attachments in picturebox but im getting error on </p>
  
  <pre class="lang-cs prettyprint-override"><code>ImageByte = (byte[]) vcom.ExecuteScalar();
  </code></pre>
  
  <p>it say</p>
  
  <blockquote>
    <p>Unable to cast object of type 'System.String' to type 'System.Byte[]'.</p>
  </blockquote>
  
  <p>here is my code</p>
  
  <pre><code>byte[] ImageByte = null;
  MemoryStream MemStream = null;
  
  OleDbConnection cn = new OleDbConnection();
  cn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/ALL/Database7.accdb";
  cn.Open();
  
  OleDbCommand command = new OleDbCommand();
  command.Connection = cn;
  string sql = "select Attachments from Contacts where ID = 1";
  OleDbCommand vcom = new OleDbCommand(sql, cn);
  
  ImageByte = (byte[]) vcom.ExecuteScalar();
  
  MemStream = new MemoryStream(ImageByte);
  pictureBox1.Image = Image.FromStream(MemStream);
  cn.Close();
  </code></pre>