Membuat Program Kontak Berfoto dengan VB.NET dan SQLServer

19 624
Biasanya jika membuat program sederhana yang menggunakan basisdata (database), program kontak-lah yang sering menjadi kasus. Karena membuat programnya kontak tidak ada proses yang berarti hanya mengisi data, simpan dan ditampilkan kembali. Kali ini saya akan berbagi membuat program kontak lengkap dengan foto dari isi kontak menggunakan bahasa pemrograman Visual Basic.NET 2008 dan basisdatanya menggunakan SQLServer2008. Program ini juga dapat dicoba menggunakan versi sebelumnya.
Ada beberapa tahapan yang harus dilakukan untuk membuat program kontak ini, yaitu :
A. Menyiapkan Basisdata
Buatlah database dengan nama yang dipilih, misal vbnet_saya. Kemudian buatlah sebuah table sesuai dengan skrip SQL dibawah ini :
CREATE TABLE [dbo].[tbl_kontak]( [id] [varchar](6) NOT NULL, [nama] [varchar](50) NULL, [alamat] [varchar](50) NULL, [phone] [varchar](50) NULL, [email] [varchar](50) NULL, [foto] [varchar](50) NULL ) ON [PRIMARY]
Jika pernyataan diatas di-eksekusi maka akan tercipta sebuah table yang bernama tbl_kontak.
B. Membuat Project Baru Visual Basic.NET
Sekarang memulai membuat project baru di Visual Basic.NET, untuk pertama kali tambahkan sebuah Class yang berisi pernyataan koneksi ke basisdata. Caranya dari menu Project, pilih Add Item, pilih Class, kemudian berinama clskoneksi.vb dan masukkan kodenya.  Kode koneksi harus disesuaikan dengan nama database (YYYY) dan nama server (XXXXX) yang digunakan.
cn = New OleDb.OleDbConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI; Persist Security Info=False;User ID=sa;Password=;Initial Catalog=YYYY;Data Source=XXXXX")
Kode dapat didownload disini.
C. Membuat Form Kontak
Setelah membuat class untuk koneksi database, selanjutnya buatlah sebuah form kontak. Untuk menambahkan form baru, klik menu Project, pilih Add Windows Form, kemudian berinama form tersebut dengan frmKontak.vb. Untuk form kontak dibutuhkan beberapa objek yaitu, Label, TextBox, Button dan ListView. Dibawah ini adalah layout form kontak :
Form Kontak
D. Kode Form Kontak
Agar form dapat berfungsi dibutuhkan kode untuk mengontrol jalannya objek form tersebut.  Jika program dieksekusi maka akan memeriksa ke database IDKontak terakhir, jika belum ada maka akan mencetak KON001, jika sudah ada maka akan menambahkan 1 angka pada angka terakhir. Pada Listview (lstKontak) akan menampilkan isi table tbl_kontak yang terurut berdasarkan nama.
Untuk menambahkan data baru cukup memasukkan nama, alamat, telepon dan email pada kolom yang ada. Untuk menambahkan foto cukup meng-klik kotak foto maka akan muncul kotak dialog untuk memilih foto yang diinginkan. Kemudian klik tombol Simpan untuk menyimpan data yang dimasukkan.
Untuk mengubah data yang diinginkan cukup memilih nama dalam ListView maka akan muncul data yang siap di-edit pada form. Lakukan perubahan terhadap nama, alamat, telepon, email dan foto, kemudian klik tombol Ubah.
Untuk menghapus data, lakukan langkah seperti meng-edit data dan menekan tombol Hapus. Sedangkan tombol Batal untuk membatalkan semua proses yang telah dilakukan. Kode lengkap dapat didownload disini.
Setiap memilih baris data pada Listview maka form akan memuat data yang dipilih dan menampilkan foto kontak.
Berikut ini adalah hasil dari eksekusi program kontak.

 

 

 

 

 

 

 

Program ini masih banyak kekurangan, sekiranya dapat disempurnakan kembali. Selamat mencoba.

Referensi :
Muhammad Sadeli, “Aplikasi Penjualan dengan Visual Basic 2008”, Maxiom, 2010

You might also like More from author

19 Comments

  1. ajatbdg says

    Mantep nih, versi javanya ada ga pak ?

  2. ajat sudrajat says

    Kunjungan keduax, baca artikel juga yang keduaxnya, maka komentarpun harus ada yang keduax. Ditunggu postingan terbarunya pak

    1. Mas Anto says

      program VB.NET atau Microsoft Visual Studio dan SQLServer sangad besar bisa mencapai 15 GB, silakan beli DVD programnya saja

      1. elmizan says

        ga boleh copy-paste y pak @-)

  3. Raka says

    iya dong man…ga boleh copas…

    tapi boleh kayaknya kalo copas buat kutipan…hehehehe
    *cari alasan buat copas…

  4. jhonry says

    Thanks mas buat share ilmunya..lagi belajar vb.net ni.,,.topiknya sama lagi.,mantap.,.,,

  5. katirefa says

    Salam kenal…
    Kalau untuk menyimpan file gambar ke Database dan menampilkannya kembali mungkin sudah banyak yang membahasnya, tapi kalau diganti dengan menyimpan file yang berupa PDF ke database dan menamplkannya kembali saya belum pernah ketemu, Nah… sekarang bisa nggak Mas Anto Aplikasi diatas diubah kebetulan saya punya kasus demikian dan sampai sekarang belum bisa saya pecahkan terutama untuk menampilkannya kembali pada form dengan VB.net dan MySql. mungkin sekiranya Mas Anto bisa bantu saya dan mungkin juga berguna bagi rekan2 yg ada disini…. Trims…

  6. katirefa says

    Ini script yg saya buat hanya untuk menyimpan file PDF ke database MySQL dan sepertinya berfungsi baik, tapi mungkin Mas Anto atau sipa saja bisa mengkoreksinya.

    Imports System.IO
    Imports MySql.Data.MySqlClient

    Public Class F_Simpan
    Inherits System.Windows.Forms.Form
    Private conn As MySqlConnection
    Private adapter As MySqlDataAdapter
    Private currFile As String = Nothing

    Private Sub bt_keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_keluar.Click
    End
    End Sub

    Private Sub bt_buka_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_buka.Click
    OpenDlg.Title = “Mencari File Data”
    If (OpenDlg.ShowDialog() = DialogResult.OK) Then
    currFile = OpenDlg.FileName
    txt_file.Text = currFile
    End If
    End Sub

    Private Sub txt_file_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txt_file.TextChanged
    If Not (txt_file.Text = String.Empty) Then
    Dim PDF = AxAcroPDF1.LoadFile(txt_file.Text)
    AxAcroPDF1.OcxState = AxAcroPDF1.OcxState
    End If
    End Sub

    Private Sub bt_simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_simpan.Click
    Dim ukuran As Integer
    Dim fs As FileStream
    Dim connStr As String
    connStr = “server=localhost;uid=root;database=datablob;”
    Try
    fs = New FileStream(currFile, FileMode.Open, FileAccess.Read)

    ukuran = fs.Length
    Dim rawData() As Byte = New Byte(ukuran) {}
    fs.Read(rawData, 0, ukuran)
    fs.Close()

    Dim sql As String = “SELECT * FROM data_blob”
    conn = New MySqlConnection(connStr)
    conn.Open()

    adapter = New MySqlDataAdapter(sql, conn)
    Dim CmdBuilder As MySqlCommandBuilder = New MySqlCommandBuilder(adapter)
    Dim ds As DataSet = New DataSet(“data_blob”)

    adapter.Fill(ds, “data_blob”)

    Dim row As DataRow = ds.Tables(“data_blob”).NewRow()
    row(“kode_file”) = txt_kode.Text
    row(“deskripsi”) = txt_des.Text

    row(“nama_file”) = Path.GetFileName(txt_file.Text)
    row(“ukuran”) = ukuran
    row(“file”) = rawData

    ds.Tables(“data_blob”).Rows.Add(row)

    adapter.Update(ds, “data_blob”)
    MsgBox(“Data berhasil disimpan”, MsgBoxStyle.Information, “Insert OK”)
    conn.Close()

    txt_kode.Text = “” : txt_des.Text = “”
    txt_file.Text = “” : txt_kode.Focus()
    ‘pic.Image = Nothing
    AxAcroPDF1.Refresh()
    Catch ex As Exception
    MsgBox(“Failed to Insert:” + ex.Message)
    End Try
    End Sub
    End Class

    Tapi untuk menampilkannya selalu gagal pesan yang muncul “Out of Memmory”

    ini script untuk menampilkannya ke Form

    Imports MySql.Data.MySqlClient
    Imports System.IO

    Public Class Tampil
    Inherits System.Windows.Forms.Form

    Private conn As MySqlConnection
    Private adapter As MySqlDataAdapter
    Private ds As DataSet

    Private Sub Tampil_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim sql As String = “SELECT * FROM data_blob”
    Dim ConnStr As String = “server=localhost;uid=root;database=datablob;”
    Try
    conn = New MySqlConnection(ConnStr)
    conn.Open()
    ds = New DataSet
    adapter = New MySqlDataAdapter(sql, conn)
    adapter.Fill(ds, “data_blop”)
    BindListControls()

    Catch ex As Exception
    MsgBox(ex.Message, MsgBoxStyle.Information, “Error”)
    End Try
    End Sub

    Private Sub BindListControls()
    cbxkode.DataSource = ds.Tables(0)
    cbxkode.DisplayMember = “kode_file”
    cbxdes.DataSource = ds.Tables(0)
    cbxdes.DisplayMember = “deskripsi”
    cbxnama.DataSource = ds.Tables(0)
    cbxnama.DisplayMember = “nama_file”
    cbxsize.DataSource = ds.Tables(0)
    cbxsize.DisplayMember = “ukuran”
    End Sub

    Private Sub btn_lihat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_lihat.Click
    Dim OpenFile As Image = Nothing
    Dim fs As FileStream = Nothing

    ‘Deklarasi variabel untuk temporary file
    Dim temp As String = “D:\” + cbxnama.Text

    ‘SQL dengan kondisi kode_file
    Dim sql As String = “SELECT * FROM data_blob WHERE kode_file='” & cbxkode.Text & “‘”
    Try
    adapter = New MySqlDataAdapter(sql, conn)
    ds = New DataSet
    adapter.Fill(ds, “data_blob”)
    Dim myRow As DataRow

    ‘Menetapkan Index data
    myRow = ds.Tables(“data_blob”).Rows(0)

    Dim DataFL() As Byte
    DataFL = myRow(“file”)
    Dim Counter As Long

    ‘Mendapatkan jumlah total Elemen array
    Counter = UBound(DataFL)
    fs = New FileStream(temp, FileMode.OpenOrCreate, FileAccess.Write)
    fs.Write(DataFL, 0, Counter)
    fs.Close()
    adapter.Dispose()

    Catch ex As Exception
    MsgBox(“Error : ” + ex.Message)
    Finally
    ‘Menampilkan File
    PDF_Tampil.OcxState = Nothing
    OpenFile = Image.FromFile(temp)
    PDF_Tampil.OcxState = PDF_Tampil.OcxState
    End Try
    End Sub

    Private Sub bt_keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_keluar.Click
    End
    End Sub

    End Class

  7. djie says

    mantap…. contoh program kayak gini yang aku cari.. thk

    1. Katirefa says

      ini script lengkapnya sudah saya lengkapi dan bisa jalan sempurna untuk menyimpan. MySql & VB.NET 2010

      Imports System.IO
      Imports MySql.Data.MySqlClient
      Imports System.Object
      Imports System.Windows.Forms
      Public Class Form1
      Inherits System.Windows.Forms.Form
      Private adapter As MySqlDataAdapter
      Private currFile As String = Nothing
      Dim table As DataTable
      Dim mysqlCmd As MySqlCommand
      Dim CommandText As MySqlCommand
      Dim ds As DataSet
      Dim fs As FileStream
      Sub Tabel()
      With LV1
      .Columns.Add(“KODE”, 0, HorizontalAlignment.Center)
      .Columns.Add(“KATEGORI”, 100, HorizontalAlignment.Center)
      .Columns.Add(“NOMOR”, 75, HorizontalAlignment.Center)
      .Columns.Add(“TAHUN”, 75, HorizontalAlignment.Center)
      .Columns.Add(“TENTANG”, 500, HorizontalAlignment.Left)
      .GridLines = True
      .FullRowSelect = True
      .View = View.Details
      End With
      End Sub
      Sub TampilLV()
      Dim DTLV As MySqlDataReader
      Try
      Conn.Open()
      Dim CC As New MySqlCommand(“select * from MASTER “, Conn)
      DTLV = CC.ExecuteReader()
      Dim i As Integer = 0
      LV1.Items.Clear()
      While DTLV.Read

      LV1.Items.Add(DTLV(“KOde”))
      LV1.Items(i).SubItems.Add(DTLV(“Kategori”))
      LV1.Items(i).SubItems.Add(DTLV(“Nomor”))
      LV1.Items(i).SubItems.Add(DTLV(“Tahun”))
      LV1.Items(i).SubItems.Add(DTLV(“Tentang”))
      i = i + 1
      End While
      Catch ex As Exception
      MessageBox.Show(ex.Message)
      Finally
      Conn.Close() ‘ must close after execute
      End Try

      End Sub
      Private Sub FrmKosong()
      TextBox1.Text = “”
      TextBox2.Text = “”
      TextBox3.Text = “”
      ComboBox1.Text = “”
      WebBrowser1.Navigate(“”)
      End Sub
      Private Sub FrmMati()
      TextBox1.Enabled = False
      TextBox2.Enabled = False
      TextBox3.Enabled = False
      ComboBox1.Enabled = False
      End Sub
      Private Sub FrmHidup()
      TextBox1.Enabled = True
      TextBox2.Enabled = True
      TextBox3.Enabled = True
      ComboBox1.Enabled = True
      End Sub
      Private Sub FrmAwal()
      FrmKosong()
      FrmMati()
      Button1.Text = “Baru”
      Button2.Text = “Edit”
      Button3.Text = “Hapus”
      Button4.Text = “Tutup”
      Button5.Text = “Open Pdf File”
      Button1.Enabled = True
      Button2.Enabled = True
      Button3.Enabled = True
      Button4.Enabled = True
      End Sub
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Tabel()
      TampilLV()
      Conn.Open()
      Dim query As String = “SELECT * FROM KTGR”
      Dim DA = New MySqlDataAdapter(query, Conn)
      Dim DS = New DataSet
      DA.Fill(DS, “KTGR”)
      ComboBox1.Text = “”
      With ComboBox1
      .DataSource = DS.Tables(“KTGR”)
      .DisplayMember = “Kategori”
      .ValueMember = “Nomor”
      .SelectedIndex = 0
      .Text = “”
      End With
      Conn.Close()
      FrmAwal()
      TextBox2.MaxLength = 4
      TextBox1.MaxLength = 4
      End Sub
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim ukuran As Integer
      Dim fs As FileStream

      If Button1.Text = “Baru” Then
      Button1.Text = “Simpan”
      Button2.Enabled = False
      Button3.Enabled = False
      Button4.Text = “Batal”
      FrmHidup()
      TextBox1.Focus()
      FrmKosong()
      Else

      If ComboBox1.Text = “” Or TextBox1.Text = “” Or TextBox2.Text = “” Or TextBox3.Text = “” Then
      MsgBox(“Data Belum Lengkap…!”, 48, “Error”)
      Else

      Try
      fs = New FileStream(currFile, FileMode.Open, FileAccess.Read)
      ukuran = fs.Length
      Dim rawData() As Byte = New Byte(ukuran) {}
      fs.Read(rawData, 0, ukuran)
      fs.Close()

      Dim sql As String = “SELECT * FROM MASTER”
      conn = New MySqlConnection(ConnectionString)
      conn.Open()

      adapter = New MySqlDataAdapter(sql, Conn)
      Dim CmdBuilder As MySqlCommandBuilder = New MySqlCommandBuilder(adapter)
      Dim ds As DataSet = New DataSet(“MASTER”)
      adapter.Fill(ds, “MASTER”)
      Dim row As DataRow = ds.Tables(“MASTER”).NewRow()
      row(“Kode”) = ComboBox1.Text + TextBox1.Text
      row(“kategori”) = ComboBox1.Text
      row(“nomor”) = TextBox1.Text
      row(“tahun”) = TextBox2.Text
      row(“tentang”) = TextBox3.Text
      row(“na_file”) = Path.GetFileName(TPath.Text)
      row(“ukuran”) = ukuran
      row(“file”) = rawData
      ds.Tables(“MASTER”).Rows.Add(row)
      adapter.Update(ds, “MASTER”)
      MsgBox(“FIle Sudah Tersimpan”, MsgBoxStyle.Information, “OK”)
      conn.Close()
      FrmAwal()
      TampilLV()
      Catch ex As Exception
      MsgBox(“Gagal Menyimpan Data Silahkan Mengulang…! ” + ex.Message)
      End Try
      End If
      End If
      End Sub
      Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      If Button2.Text = “Edit” Then
      Button2.Text = “Simpan”
      Button1.Enabled = False
      Button3.Enabled = False
      Button4.Text = “Batal”
      FrmHidup()
      TextBox1.Focus()
      Else
      If TextBox1.Text = “” Or TextBox2.Text = “” Then
      MsgBox(“Maaf Data Masih Kurang”, 48, “Error”)
      Else
      Conn.Open()
      Dim SQLUbah As String
      SQLUbah = “Update Master Set Kategori='” & ComboBox1.Text & “‘,Nomor='” & TextBox1.Text & “‘,Tahun='” _
      & TextBox2.Text & “‘,Tentang='” & TextBox3.Text & “‘Where Kode='” & LBKODE.Text & “‘”
      Cmd = New MySqlCommand(SQLUbah, Conn)
      Cmd.ExecuteNonQuery()
      MsgBox(“Data Telah Di Ubah”, MsgBoxStyle.OkOnly + MsgBoxStyle.Information, “Sukses”)
      FrmAwal()
      Conn.Close()
      TampilLV()
      End If
      End If
      End Sub
      Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
      If TextBox1.Text = “” Then
      MsgBox(“Maaf Tidak ada data yang akan dihapus”, 48, “Perhatian”)
      Else
      Dim Pesan As String
      Pesan = MsgBox(“Yakin akan dihapus”, MsgBoxStyle.YesNo, “Konfirmasi”)
      If Pesan = vbYes Then
      Conn.Open()
      Dim SQLHapus As String
      SQLHapus = “Delete From Master Where Kode='” & LBKODE.Text & “‘”
      Cmd = New MySqlCommand(SQLHapus, Conn)
      Cmd.ExecuteNonQuery()
      Conn.Close()
      FrmAwal()
      TampilLV()
      End If
      End If
      End Sub
      Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
      Select Case Button4.Text
      Case “Tutup”
      Close()
      Case “Batal”
      FrmAwal()
      End Select
      End Sub
      Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
      OpenDlg.Title = “Mencari File Data”
      If (OpenDlg.ShowDialog() = DialogResult.OK) Then
      currFile = OpenDlg.FileName
      TPath.Text = currFile
      TextBox1.Enabled = True
      TextBox2.Enabled = True
      TextBox3.Enabled = True
      End If
      End Sub
      Private Sub Lv1_DoubleClick1(ByVal sender As Object, ByVal e As System.EventArgs) Handles LV1.DoubleClick
      With Me.LV1
      LBKODE.Text = .SelectedItems(0).SubItems(0).Text
      ComboBox1.Text = .SelectedItems(0).SubItems(1).Text
      TextBox1.Text = .SelectedItems(0).SubItems(2).Text
      TextBox2.Text = .SelectedItems(0).SubItems(3).Text
      TextBox3.Text = .SelectedItems(0).SubItems(4).Text
      End With
      TampilPdf()
      Button4.Text = “Batal”
      End Sub
      Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
      If Not ((e.KeyChar >= “0” And e.KeyChar = “0” And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then
      e.Handled() = True
      End If
      End Sub
      Sub TampilPdf()
      Dim fs As FileStream = Nothing

      Dim temp As String = "D:DataSiskumTemp" + LBKODE.Text

      Dim sql As String = "SELECT * FROM Master WHERE Kode='" & LBKODE.Text & "'"
      Try
      adapter = New MySqlDataAdapter(sql, Conn)
      ds = New DataSet
      adapter.Fill(ds, "Master")
      Dim myRow As DataRow

      myRow = ds.Tables("Master").Rows(0)

      Dim DataPDF() As Byte
      DataPDF = myRow("file")
      Dim Counter As Long

      Counter = UBound(DataPDF)
      fs = New FileStream(temp, FileMode.OpenOrCreate, FileAccess.Write)
      fs.Write(DataPDF, 0, Counter)
      fs.Close()
      adapter.Dispose()

      Catch ex As Exception
      MsgBox("Error : " + ex.Message)
      Finally
      WebBrowser1.Refresh()
      WebBrowser1.Navigate(temp)
      End Try
      End Sub
      Private Sub TPath_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TPath.TextChanged
      If Not (TPath.Text = String.Empty) Then
      WebBrowser1.Navigate(TPath.Text)
      End If
      End Sub

      End Class

  8. Katirefa says

    Ini script untuk menampilkannya kembali

    Imports System.IO
    Imports MySql.Data.MySqlClient
    Imports System.Object
    Imports System.Windows.Forms
    Public Class Form2
    Inherits System.Windows.Forms.Form
    Private adapter As MySqlDataAdapter
    Private currFile As String = Nothing
    Dim table As DataTable
    Dim mysqlCmd As MySqlCommand
    Dim CommandText As MySqlCommand
    Dim ds As DataSet
    Dim fs As FileStream
    Sub Tabel()
    With LV1
    .Columns.Add(“KODE”, 0, HorizontalAlignment.Left)
    .Columns.Add(“KATEGORI”, 200, HorizontalAlignment.Left)
    .Columns.Add(“NOMOR”, 75, HorizontalAlignment.Left)
    .Columns.Add(“TAHUN”, 75, HorizontalAlignment.Left)
    .Columns.Add(“TENTANG”, 500, HorizontalAlignment.Left)
    .GridLines = True
    .FullRowSelect = True
    .View = View.Details
    End With
    End Sub
    Sub TampilLV()
    Dim DTLV As MySqlDataReader
    Try
    Conn.Open()
    Dim CC As New MySqlCommand(“select * from MASTER “, Conn)
    DTLV = CC.ExecuteReader()
    Dim i As Integer = 0
    LV1.Items.Clear()
    While DTLV.Read
    LV1.Items.Add(DTLV(“KODE”))
    LV1.Items(i).SubItems.Add(DTLV(“Kategori”))
    LV1.Items(i).SubItems.Add(DTLV(“Nomor”))
    LV1.Items(i).SubItems.Add(DTLV(“Tahun”))
    LV1.Items(i).SubItems.Add(DTLV(“Tentang”))
    i = i + 1
    End While
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    Finally
    Conn.Close() ‘ must close after execute
    End Try

    End Sub
    Private Sub FrmKosong()
    ComboBox1.Text = “”
    TextBox1.Text = “”
    TextBox2.Text = “”
    TextBox3.Text = “”
    WebBrowser1.Navigate(“”)
    End Sub
    Private Sub Form2_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
    DataCombo()
    TampilLV()
    End Sub
    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Tabel()
    End Sub
    Private Sub LV1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles LV1.DoubleClick
    With Me
    LBKODE.Text = LV1.SelectedItems(0).SubItems(0).Text
    t4.Text = LV1.SelectedItems(0).SubItems(1).Text
    T1.Text = LV1.SelectedItems(0).SubItems(2).Text
    t2.Text = LV1.SelectedItems(0).SubItems(3).Text
    t3.Text = LV1.SelectedItems(0).SubItems(4).Text
    End With
    ComboBox1.Text = t4.Text
    TextBox1.Text = T1.Text
    TextBox2.Text = t2.Text
    TextBox3.Text = t3.Text
    TampilPdf()
    End Sub
    Sub TampilPdf()
    Dim fs As FileStream = Nothing

    Dim temp As String = “D:DataSiskumTemp” + LBKODE.Text

    Dim sql As String = “SELECT * FROM Master WHERE Kode='” & LBKODE.Text & “‘”
    Try
    adapter = New MySqlDataAdapter(sql, Conn)
    ds = New DataSet
    adapter.Fill(ds, “Master”)
    Dim myRow As DataRow

    myRow = ds.Tables(“Master”).Rows(0)

    Dim DataPDF() As Byte
    DataPDF = myRow(“file”)
    Dim Counter As Long

    Counter = UBound(DataPDF)
    fs = New FileStream(temp, FileMode.OpenOrCreate, FileAccess.Write)
    fs.Write(DataPDF, 0, Counter)
    fs.Close()
    adapter.Dispose()

    Catch ex As Exception
    MsgBox(“Error : ” + ex.Message)
    Finally
    WebBrowser1.Refresh()
    WebBrowser1.Navigate(temp)
    End Try
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    FrmKosong()
    Tabel()
    TampilLV()
    End Sub
    Sub DataCombo()
    Conn.Open()
    Dim query As String = “SELECT * FROM KTGR”
    Dim DA = New MySqlDataAdapter(query, Conn)
    Dim DS = New DataSet
    DA.Fill(DS, “KTGR”)

    With ComboBox1
    .DataSource = DS.Tables(“KTGR”)
    .DisplayMember = “Kategori”
    .ValueMember = “Nomor”
    .SelectedIndex = 0
    End With
    ComboBox1.Text = “”
    Conn.Close()
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

    Dim DTLV As MySqlDataReader
    Try
    Conn.Close()
    Conn.Open()
    Dim CC As New MySqlCommand(“Select * From MASTER where Kategori Like’%” & ComboBox1.Text & “%'”, Conn)
    DTLV = CC.ExecuteReader()
    Dim i As Integer = 0
    LV1.Items.Clear()
    While DTLV.Read
    LV1.Items.Add(DTLV(“KODE”))
    LV1.Items(i).SubItems.Add(DTLV(“Kategori”))
    LV1.Items(i).SubItems.Add(DTLV(“Nomor”))
    LV1.Items(i).SubItems.Add(DTLV(“Tahun”))
    LV1.Items(i).SubItems.Add(DTLV(“Tentang”))
    i = i + 1
    End While
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    Finally
    Conn.Close()
    End Try
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    Dim DTLV As MySqlDataReader
    Try
    Conn.Open()
    Dim CC As New MySqlCommand(“Select * From MASTER where Nomor Like’%” & TextBox1.Text & “%'”, Conn)
    DTLV = CC.ExecuteReader()
    Dim i As Integer = 0
    LV1.Items.Clear()
    While DTLV.Read
    LV1.Items.Add(DTLV(“KODE”))
    LV1.Items(i).SubItems.Add(DTLV(“Kategori”))
    LV1.Items(i).SubItems.Add(DTLV(“Nomor”))
    LV1.Items(i).SubItems.Add(DTLV(“Tahun”))
    LV1.Items(i).SubItems.Add(DTLV(“Tentang”))
    i = i + 1
    End While
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    Finally
    Conn.Close()
    End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Close()
    End Sub
    End Class

  9. Programmer Pemula says

    Mas, koneksi vb.net ke sql servernya gmana?

  10. djiesoft says

    ide nya bagus dan kreatif… bagus sekali aplikasinya

  11. Ardiansyah says

    bang, untuk kode membuat form kontak, di liat di mana,,??

  12. Alfredi says

    Mas link downloadnya mati,mas mohon kirimkan ke email saya dong program cara membuat kontak berfotonya,bagus banget mas,please ya…email : priasiantar@yahoo.com, ditunggu mas,terimakasih sebelumnya.

Leave A Reply

Your email address will not be published.

10 − six =