更新时GDI +中发生一般错误

时间:2017-04-25 20:35:28

标签: vb.net gdi+

当我更新表单时,只有在我不更新(更改)图像时才会出现此错误 当我使用新图片更新时,我没有出现此错误。

Try
    Dim mstream As New System.IO.MemoryStream()
    PictureBox1.Image = New Bitmap(Image.FromStream(mstream))
    Dim arrImage() As Byte = mstream.GetBuffer()
    mstream.Close()

    MysqlConn.Close()
    MysqlConn.Open()
    COMMAND.Connection = MysqlConn
    COMMAND.CommandText = "update product set 
        id_maker=@Value1, 
        foto=@foto  
        where id = '" & TextBox1.Text & "'"
    COMMAND.Parameters.AddWithValue("@Value1", If(String.IsNullOrEmpty(ComboBox1.Text), DBNull.Value, ComboBox1.Text))

    COMMAND.Parameters.AddWithValue("@foto", arrImage)
    READER = COMMAND.ExecuteReader
    MessageBox.Show("Datos Guardados")
    MysqlConn.Close()
Catch ex As Exception
    MessageBox.Show(ex.Message)
Finally
    MysqlConn.Dispose()
End Try
MysqlConn.Close()

1 个答案:

答案 0 :(得分:-2)

我试试这个并且工作。

Dim mstream As New System.IO.MemoryStream()
                'PictureBox1.Image = New Bitmap(Image.FromStream(mstream))
                PictureBox1.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
                Dim arrImage() As Byte = mstream.GetBuffer()