title: How to save a PictureBox Image in DB
body: <p>when i try to capture an image to my webcam in VB.NET using Emgu and copy it into another PictureBox in another Form with this code <code>Form23.PictureBox1.Image = New Bitmap(captureImageBox.Image)</code> and try to save it in my database, it doesn't save and an error appears like this <code>Empty path name is not legal</code> but the picture is there and copied from the webcam PictureBox.</p>
  
  <p>this is my code in saving the image in database:</p>
  
  <pre><code>Dim a As OpenFileDialog = New OpenFileDialog
  
  SQL = "UPDATE candidate SET photo='" photo=@photo WHERE idn='" &amp; cd &amp; "'"
          Dim sqlCommand As New MySqlCommand
          sqlCommand.Parameters.Add("@photo", MySqlDbType.LongBlob)
          sqlCommand.Parameters("@photo").Value = IO.File.ReadAllBytes(a.FileName)
  
         With sqlCommand
              .CommandText = SQL
              .Connection = sConnection
              .ExecuteNonQuery()
  </code></pre>
  
  <p>but if i save an image from <code>OpenFileDialog</code> it saves. why can't it be?hmm
  is there a problem in my code in copying the Image from PictureBox to another?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>tried this but it doesn't work either:</p>
  
  <p>Replaced this:</p>
  
  <pre><code>sqlCommand.Parameters.Add("@photo", MySqlDbType.LongBlob)
          sqlCommand.Parameters("@photo").Value = IO.File.ReadAllBytes(a.FileName)
  
         With sqlCommand
              .CommandText = SQL
              .Connection = sConnection
              .ExecuteNonQuery()
  </code></pre>
  
  <p>with this one:</p>
  
  <pre><code>Dim ms As New IO.MemoryStream()
  PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
  Dim data As Byte() = MS.GetBuffer()
  Dim p As New MySqlParameter("@photo", MySqlDbType.LongBlob)
  p.Value = data
  cmd.Parameters.Add(p)
  sqlCommand.Parameters.Add("@cd", MySqlDbType.Int32).Value = cd
  cmd.ExecuteNonQuery()
  </code></pre>