[ask | vb net] kak saya mau menyimpan gambar ke folder, jadi - TopicsExpress



          

[ask | vb net] kak saya mau menyimpan gambar ke folder, jadi yang disimpan ke database mysql hanya lokasi file nya saja. penyimpanan berhasil namun ketika datagridview di klik foto tidak muncul di picturebox1. mohon pencerahannya . cara retrieve gambar nya. Imports System.Data.Odbc Public Class Siswa Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Call Koneksi() Call TampilGrid() End Sub Sub TampilGrid() da = New OdbcDataAdapter(select * from table1, Conn) DS = New DataSet DA.Fill(DS, TBLBarang) DGV.DataSource = DS.Tables(TBLBarang) DGV.Columns(2).Visible = False DGV.ReadOnly = True End Sub Sub Kosongkan() On Error Resume Next txtkode.Clear() txtkode.Enabled = True txtnama.Clear() Lblfilefoto.Text = PictureBox1.Load(Lblfilefoto.Text) txtkode.Focus() End Sub Sub DataBaru() On Error Resume Next txtnama.Clear() Lblfilefoto.Text = PictureBox1.Load(Lblfilefoto.Text) txtnama.Focus() End Sub Private Sub TxtKode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtkode.KeyPress txtkode.MaxLength = 3 If e.KeyChar = Chr(13) Then cmd = New OdbcCommand(select * from table1 where Kode= & txtkode.Text & , Conn) rd = cmd.ExecuteReader rd.Read() If rd.HasRows Then Try txtnama.Text = rd.Item(Nama) Lblfilefoto.Text = rd.Item(Foto) PictureBox1.Load(Lblfilefoto.Text) PictureBox1.SizeMode = PictureBoxSizeMode.Zoom txtnama.Focus() Catch ex As Exception MsgBox(foto tidak dapat ditampilkan) End Try Else Call DataBaru() End If End If End Sub Private Sub Txtnama_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtnama.KeyPress txtnama.MaxLength = 30 If e.KeyChar = Chr(13) Then Button1.Focus() End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If txtkode.Text = Or txtnama.Text = Or Lblfilefoto.Text = Then MsgBox(Data belum lengkap) If txtkode.Text = Then txtkode.Focus() If txtnama.Text = Then txtnama.Focus() If Lblfilefoto.Text = Then Try OpenFileDialog1.Filter = (*.jpg)|*.jpg|(*.bmp)|*.bmp|All files (*.*)|*.* OpenFileDialog1.ShowDialog() PictureBox1.Load(OpenFileDialog1.FileName) PictureBox1.SizeMode = PictureBoxSizeMode.Zoom Lblfilefoto.Text = OpenFileDialog1.FileName Catch ex As Exception MsgBox(ex.Message) End Try End If Else On Error Resume Next cmd = New OdbcCommand(select * from table1 where Kode= & txtkode.Text & , Conn) rd = cmd.ExecuteReader rd.Read() If Not rd.HasRows Then Try Dim simpan As String = insert into table1 values ( & txtkode.Text & , & txtnama.Text & , & Lblfilefoto.Text & ) cmd = New OdbcCommand(simpan, Conn) Call Kosongkan() Call TampilGrid() txtkode.Focus() Catch ex As Exception MsgBox(ex.Message) End Try Else Dim edit As String = Update table1 set Nama= & txtnama.Text & ,Foto= & Lblfilefoto.Text & where Kode= & txtkode.Text & cmd = New OdbcCommand(edit, Conn) cmd.ExecuteNonQuery() Call Kosongkan() Call TampilGrid() txtkode.Focus() End If End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If txtkode.Text = Then MsgBox(KODE HARUS DIISI DULU, SILAKAN PILIH DATA DLM GRID) txtkode.Focus() Exit Sub Else If MessageBox.Show(Yakin akan dihapus..?, , MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then Dim hapus As String = delete * from table1 where Kode= & txtkode.Text & cmd = New OdbcCommand(hapus, Conn) cmd.ExecuteNonQuery() Call Kosongkan() Call TampilGrid() Else Call Kosongkan() End If End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Call Kosongkan() txtkode.Focus() End Sub Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click OpenFileDialog1.Filter = (*.jpg)|*.jpg|(*.bmp)|*.bmp|All files (*.*)|*.* OpenFileDialog1.ShowDialog() PictureBox1.Load(OpenFileDialog1.FileName) PictureBox1.SizeMode = PictureBoxSizeMode.Zoom Lblfilefoto.Text = OpenFileDialog1.FileName End Sub End Class
Posted on: Sun, 20 Jul 2014 08:21:32 +0000

Trending Topics



Recently Viewed Topics




© 2015