KERJA IT - COMPUTER

Markas Rabbani Surabaya Jl.Pucang Anom Timur No. 14 Surabaya Telp. 08123015071 Email : Markas_rabbani_sby@yahoo.co.id

  • RSS
  • Google +
  • Facebook

Popular Posts

IDHOSTINGER memang OK
Radio - TV OnLine
Asyiiikk Bro

Translate Google

About Me

Foto saya

1. Kerja di Perusahaan Jualan Computer 2. Konsultan Management and Software House di Jakarta Jl. Kemang Raya Jakarta Selatan, PT Sumber Saran Sempurna 3. Honor di Kantor Bea dan Cukai TG. Perak dan Juanda Surabaya 4. Free Line di berbagai Instansi sebagai Programmer 5. Mulai awal tahun 2007 sampai sekarang kerja di Rabbani Profesor Kerudung Instan Jl. Dharmawangsa 98 A Surabaya

Popular Posts

Markas Rabbani Surabaya

HOSTINGER

Web Hosting

KOMINITAS VFP

IP ADDRESS INFO

IP

Google+ Followers

Total Tayangan Halaman

HOSTINGER

Web Hosting

Prof DR KH Said Aqil Sirodj - Ketua PB NU

Gus Mus - Prof DR KH Said Aqil Sirodj - Alm Gus Dur

HOSTINGER Web Gratis Tanpa Iklan

Gak Percaya Buktikan

Griya Asy-Syifa

Jl Suromulang Timur II/18 Perum Citra Surodinawan Estate Kota Mojokerto Contac : 081231821800, 08814353000, 085746201881 Pin BB : 24D0B84C e-mail : ariesmojokerto@gmail.com

HOSTINGER Gratis tanpa Iklan

Web Hosting GRATIS dI Indonesia Tanpa Iklan

WaliSongo

Babat alas Tanah Jawa - Pengikut Nabi Muhammad saw - NU

Senin, 08 Oktober 2012

MEREKAM IMAGE KE MYSQL - VB 2010

PEREKAM DATA IMAGE/ FOTO KE DALAM MYSQL PAKAI VB 2010

1. Kita buat dulu Table nya saya pakai XAMPP-MYSQL menggunakan MYSQL-Front

2. Kita bikin modulnya setelah buat Form
3. Kita Connectkan DataBase MYSQL dngan VB 2010 dengan menggunakan
    Connector MYSQL versi NET 6.5.4
4. Kita siapkan : PictureBox,DataGridView, OpenFileDialog, Button, TextBox 4.

Kita buat Codingnya - lalu kita jalankan Selesai

Lihat Gambar :

Persiapan Form 


Hasil yg di Rekam di Tabel MYSQL 


Hasil Perekaman Gambar / Foto 


Ini Rincian Codingnya Untuk yg di Module : 


Imports MySql.Data.MySqlClient
Imports System.Data
Module modul_foto
    Public cmd As New MySqlCommand
    Public dadapter As New MySqlDataAdapter
    Public datardr As MySqlDataReader
    Public strSql As String
    Dim serv As String = "Server=192.168.1.8;"
    Dim dbase As String = "Database=jualan;"
    Dim uid As String = "uid=root;"
    Dim pwd As String = "pwd=root;"
    Dim ConString = serv & dbase & uid & pwd
    Public db As New MySqlConnection(ConString)
    Public Sub konek()
        Try
            tutupDB()
            db.Open()
            MsgBox("Koneksi DataBase berhasil dilakukan")
        Catch ex As MySqlException
            MsgBox(ex.Message)
            MsgBox("Koneksi tidak berhasil dilakukan")
        End Try
    End Sub
    Public Sub tutupDB()
        If db.State = ConnectionState.Open Then
            db.Close()
        End If
    End Sub

End Module



Ini Coding untuk yang di Form1 :



Imports System.IO
Imports MySql.Data.MySqlClient
Public Class Form1
    Private path As String = ""
    Private strSql As String = String.Empty
    Dim FileName As String

    Private Sub coneksi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles coneksi.Click
        konek()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            With ofdphoto
                .Title = "Browse Gambar"
                .FileName = "Pilih Gambar"
                .Filter = "Type(*.jpg, *.jpeg, *.bmp, *.gif, *.png)|*.jpg; *.jpeg; *.bmp; *gif; *.png"
                .ShowDialog()
                path = .FileName
                txtlokasi.Text = path
                picphoto.Image = Image.FromFile(path)
                picphoto.SizeMode = PictureBoxSizeMode.StretchImage
                'biar tampilan image pas dengan kotak image yang di sediakan
            End With
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
        End Try

    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        konek()
        ' Dim FileName As String = "E:\ter\tantri.jpg"
        Dim cmd As New MySqlCommand("INSERT INTO mahasiswa (npm, nama, foto) VALUES (@1, @2, @3)", db)
        'strSql = "INSERT INTO mahasiswa (npm, nama, foto) VALUES (@1, @2, @3)" ' ini perintah insert biasa
        ' Using cmd As New MySqlClient.MySqlCommand(strSql, db)
        With cmd
            .Parameters.Clear()
            .Parameters.AddWithValue("@1", txtnim.Text.Trim) ' npm
            .Parameters.AddWithValue("@2", txtnama.Text.Trim) ' nama
            .Parameters.AddWithValue("@3", IO.File.ReadAllBytes(txtlokasi.Text)) ' foto

            .ExecuteNonQuery()
        End With
        ' End Using

        MessageBox.Show("Data sudah disimpan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information)

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Try
            tutupDB()
            db.Open()

        Catch ex As MySqlException
            MsgBox(ex.Message)
            MsgBox("Koneksi tidak berhasil dilakukan")
            Exit Sub
        End Try

        Try
            strSql = "SELECT foto FROM mahasiswa WHERE npm = @1"
            cmd.CommandText = strSql
            cmd.Connection = db
            dadapter.SelectCommand = cmd
            ' datar = cmd.ExecuteReader
            cmd.Parameters.Clear()
            cmd.Parameters.AddWithValue("@1", txtnim.Text) ' npm
            datardr = cmd.ExecuteReader

            If datardr.HasRows Then
                'datardr.Read()
                If datardr.Read() Then
                    'txtnim.Text = datardr("npm")
                    'txtnama.Text = datardr("nama")
                    Dim ms As New IO.MemoryStream(CType(datardr.Item("foto"), Byte()))
                    picphoto.Image = Image.FromStream(ms) ' tampilkan gambarnya
                End If
            End If
        Catch ex As Exception

        End Try

    End Sub
End Class









Tidak ada komentar:

Posting Komentar