title: how to update picture in mysql database
body: <p>i have tried this code here to insert and show picture from database to picturebox : stackoverflow.com/questions/5624760/store-picture-to-database-retrieve-from-db-into-picturebox</p>
  
  <p>and yeah, it is working , but when i tried to do update using the same syntax as insert it got this error :</p>
  
  <p><a href="https://i.stack.imgur.com/hKMCk.png" rel="nofollow"><img src="https://i.stack.imgur.com/hKMCk.png" alt="enter image description here"></a></p>
  
  <p>this is the insert syntax i use :</p>
  
  <pre><code>Dim FileSize As UInt32
  Dim mstream As New System.IO.MemoryStream()
  gambar.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)  
  Dim arrImage() As Byte = mstream.GetBuffer()
  
  FileSize = mstream.Length
  
  mstream.Close()
  
  call konek
  strSQL = "insert into tbmahasiswa VALUES ('" &amp; _
                      txtNIM.Text &amp; "','" &amp; _
                      txtNama.Text &amp; "','" &amp; _
                      Format(dtpTanggal.Value, "yyyy-MM-dd") &amp; "','" &amp; _
                      txtAlamat.Text &amp; "','" &amp; _
                      cboJurusan.Text &amp; "',@gambar)"
  com = New MySql.Data.MySqlClient.MySqlCommand(strSQL, conn)
  
  With com
    .Parameters.AddWithValue("@gambar", arrImage)
    .ExecuteNonQuery()
  End With
  </code></pre>
  
  <p>and this the code i use to show picture from database to picture box :</p>
  
  <pre><code>Dim imgData As Byte()
  
  call konek
  strSQL = "select * from tbMahasiswa where NIM ='" &amp; txtNIM.Text &amp; "'"
  com = New MySql.Data.MySqlClient.MySqlCommand(strSQL, conn)
  Using rd = com.ExecuteReader
  
    rd.Read()
    If rd.HasRows Then
              txtNama.Text = rd.Item(1)
              dtpTanggal.Value = rd.Item(2)
              txtAlamat.Text = rd.Item(3)
  
              imgData = TryCast(rd.Item(5), Byte())
  
              If imgData IsNot Nothing Then
  
                  Using ms As New MemoryStream(imgData)
  
                      gambar.Image = CType(Image.FromStream(ms), Image)
  
                  End Using
              End If
  
          End If
  
      End Using
  </code></pre>
  
  <p>Both Insert and Retrieving Picture Code above is Working ! , and then i use this code for update :</p>
  
  <pre><code>Dim FileSize As UInt32
  Dim mstream As New System.IO.MemoryStream()
  gambar.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)  
  Dim arrImage() As Byte = mstream.GetBuffer()
  
  FileSize = mstream.Length
  
  mstream.Close()
  
  call konek
  strSQL = "update tbmahasiswa set Nama ='" &amp; txtNama.Text &amp; _
                       "', TglLahir ='" &amp; Format(dtpTanggal.Value, "yyyy-MM-dd") &amp; _
                       "', Alamat ='" &amp; txtAlamat.Text &amp; _
                       "', Jurusan ='" &amp; cboJurusan.Text &amp; _
                       "', gambar =' @gambar" &amp; _
                       "' where NIM ='" &amp; txtNIM.Text &amp; "'"
              com = New MySql.Data.MySqlClient.MySqlCommand(strSQL, conn)
  
  With com
    .Parameters.AddWithValue("@gambar", arrImage)
    .ExecuteNonQuery()
  End With
  </code></pre>
  
  <p>and then i got the error like in the picture above, all other data is correctly saved except the picture, it become some unknown file blob 8 KB size.</p>
  
  <p>i'm still newbie at insert , update, delete picture in VB, please can you tell me what is wrong with the Update syntax code , is it already true but i'm missing something ? or is it totally wrong with the syntax ? please i need your guide here...</p>
  
  <p>UPDATE :
  actually there is "call konek" above "STRSQL" in the code, "konek" have the code for open the mysql connection,i put it in the separate module, here the full code in my module :</p>
  
  <pre><code>Module modKoneksi
  
  Public conn As New MySql.Data.MySqlClient.MySqlConnection
  Public rd As MySql.Data.MySqlClient.MySqlDataReader
  Public com As MySql.Data.MySqlClient.MySqlCommand
  
  Public strSQL As String
  
  Public Sub konek()
      conn.Close()
      strSQL = "server='localhost';user='root';pwd='';database='dbsekolah';"
      Try
          conn.ConnectionString = strSQL
          conn.Open()
  
      Catch ex As MySql.Data.MySqlClient.MySqlException
          MsgBox(ex.Message)
          End
      End Try
  End Sub
  End Module
  </code></pre>
  
  <p>hope this makes you easier to solve my problem</p>