simpan gambar di vb.net dengan type bloob di mysql
Dim connstr As String
connstr = "server=localhost;user id=root;password=;database=aldie;"
Try
'membaca isi steram
fs = New FileStream(currfile, FileMode.Open, FileAccess.Read)
'mendapatkan ukuran file
ukuran = fs.Length
Dim rawdata() As Byte = New Byte(ukuran) {}
fs.Read(rawdata, 0, ukuran)
fs.Close()
Dim sql As String = "select * from jenisbarang"
conn = New MySqlConnection(connstr)
conn.Open()
adapter = New MySqlDataAdapter(sql, conn)
Dim cmdbuilder As MySqlCommandBuilder = New MySqlCommandBuilder(adapter)
Dim ds As DataSet = New DataSet("jenisbarang")
'mengsi data adapter
adapter.Fill(ds, "jenisbarang")
Dim row As DataRow = ds.Tables("jenisbarang").NewRow()
row("kdjenis") = txtkdjenis.Text
row("nmjenis") = txtnmjenis.Text
row("nama_file") = Path.GetFileName(txtphoto.Text)
row("ukuran") = ukuran
row("file") = rawdata
'meemasukan row
ds.Tables("jenisbarang").Rows.Add(row)
'menyimpan perubahan ke database
adapter.Update(ds, "jenisbarang")
MsgBox("data berhasil di masukan", MsgBoxStyle.Information, "insertok")
mycn.tutupkoneksi()
bersihkantext()
'clear textbox dan piccturebox
txtkdjenis.Text = "" : txtnmjenis.Text = ""
txtphoto.Text = "" : txtkdjenis.Focus()
Catch ex As Exception
MsgBox("failed to insert : " + ex.Message)
End Try
narsis dikit ga papa kan..hehe