please help me.... how save image from picturebox, and how load image in event datagridview clik to picturebox,i use mysql database, this is my coding.. :
note : pb=picturebox, dg=datagridview, baranggambar longblob= my name fild image
'this is my coding for save :
Sub proses(ByVal sql As String)
Dim FileSize As UInt32
Dim mstream As New System.IO.MemoryStream()
pb.Image.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim arrImage() As Byte = mstream.GetBuffer()
FileSize = mstream.Length
mstream.Close()
MsgBox(FileSize)
kon.Close()
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = sql
perintah.Parameters.AddWithValue("photo", arrImage)
perintah.ExecuteNonQuery()
MsgBox("Data berhasil di proses!!!", MsgBoxStyle.Information, "info")
kon.Close()
End Sub
Private Sub Bsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bsimpan.Click
If (Txtidbrg.Text = "") Or (Txtnamabrg.Text = "") Or (Txtharga.Text = "") Or (Txtmodal.Text = "") Or (Txtkategori.Text = "") Or (Txtstok.Text = "") Then
MsgBox("lengkapi dulu data bertanda *...", MsgBoxStyle.Information, "info")
Exit Sub
End If
If Bsimpan.Text = "Simpan" Then
Bsimpan.Text = "update"
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = "select * from barang where barangid='" & Txtidbrg.Text & "'"
cek = perintah.ExecuteReader
cek.Read()
If cek.HasRows Then
If cek.Item("barangid") <> 0 Then
MsgBox("kode sudah ada harap diganti", MsgBoxStyle.Information)
End If
Else
Call proses("insert into barang(barangid,barangnama,barangkategori,barangidgambar,baranggambar,barangmodal,barangharga,barangstok)values('" & Txtidbrg.Text & "','" & Txtnamabrg.Text & "','" & Txtkategori.Text & "','" & Txtgambar.Text & "','" & "photo" & "' ,'" & Txtmodal.Text & "','" & Txtharga.Text & "','" & Txtstok.Text & "')")
cek.Close()
kon.Close()
End If
'this my coding for load :
Private Sub dg_CellContentClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dg.CellContentClick
Dim i As Integer
i = dg.CurrentRow.Index
If dg.CurrentCell.Value.ToString = "" Then
MsgBox("data tidak ada gan...")
Exit Sub
Else
kon.Open()
perintah.Connection = kon
perintah.CommandType = CommandType.Text
perintah.CommandText = "SELECT * FROM barang where barangid='" & dg.CurrentRow.Cells(0).Value.ToString & "'"
cek = perintah.ExecuteReader
cek.Read()
If cek.HasRows Then
pb.Image = pbGetDataToImage(cek.Item("baranggambar"))
End If
cek.Close()
kon.Close()
Txtidbrg.Text = dg.Rows.Item(i).Cells(0).Value
Txtnamabrg.Text = dg.Rows.Item(i).Cells(1).Value
Txtkategori.Text = dg.Rows.Item(i).Cells(2).Value
Txtgambar.Text = dg.Rows.Item(i).Cells(3).Value
Txtstok.Text = dg.Rows.Item(i).Cells(4).Value
Txtmodal.Text = dg.Rows.Item(i).Cells(5).Value
Txtharga.Text = dg.Rows.Item(i).Cells(6).Value
End If