Cara Membuat Aplikasi Data Pegawai Sederhana dengan Visual Studio 2013 & MySQL Server


Hallo karna banyak yang request dan nanya tentang membuat aplikasi data pegawai akhir nya admin bisa sedikit sharing membuat aplikasi sederhana data pegawai xD

Ini contoh screenshot aplikasi sederhana nya :




Oke apa saja yang harus dibutuhkan ?

  • Laptop / Kompi 
  • Microsoft Visual Studio 2013
  • SQL Server 2008 atau 2014

Langkah membuat aplikasi :

  • Buka Visual Studio 2013 dan desain sesuai gambar diatas
  • Buat Database menggunakan SQL Server 2008 / 2014 dengan nama Database nya Pegawai dan nama Table nya sebagai format berikut
  1. ID_PEG nvarchar(50)
  2. NAMA nvarchar(50)
  3. NO_TLP nvarchar(50)
  4. ALAMAT nvarchar(50)
  • Klik pada project /Add Module / ber nama Koneksi
  • Ketikan kode dibawah ini

Imports System.Data.SqlClient
Imports System.Data
Module Koneksi
    Public strconn As String = "Data Source=XSSDP-NETWORKS;Initial Catalog=Pegawai;Integrated Security=True;Pooling=False"
    Public oleconn As SqlConnection
    Public leconn As SqlConnection
    Public cmmd As SqlCommand
    Public comm As SqlCommand
    Public cmm As SqlCommand
    Public cmmmd As SqlCommand
    Public dreder As SqlDataReader
    Public reder As SqlDataReader
    Public dreader As SqlDataReader
    Public objdataadapter As SqlDataAdapter
    Public objDatatabel As New DataTable
    Public objdataset As New DataSet
    Public username, Password, Strsql, StrTemp, StrVal As String
    Public sql As String = ""
    Public sql2 As String = ""
    Public cmd As SqlCommand

    Public Function Koneksi() As SqlConnection
        Dim Conn As New SqlConnection
        Conn = New SqlConnection(strconn)
        Conn.Open()
        Return Conn
    End Function
    Public Sub BukaKoneksi()
        Try
            oleconn = New SqlConnection(strconn)
            oleconn.Open()
            MsgBox("Koneksi Sukses......!!!", MsgBoxStyle.Information, "Pesan")
        Catch ex As Exception
            MsgBox("Koneksi Error.....!!!", MsgBoxStyle.Exclamation, "Warning")
        End Try
    End Sub
    Public Sub Konek()
        Try
            oleconn = New SqlConnection(strconn)
            oleconn.Open()
        Catch ex As Exception
            oleconn.Close()
        End Try
    End Sub
    Public Sub Buka()
        oleconn = New SqlConnection(strconn)
        If leconn.State <> ConnectionState.Closed Then oleconn.Close()
        oleconn.Open()
    End Sub
End Module

Ingat baris yang admin warna merah itu adalah path dimana database dalam laptop / komputer kalian masing-masing



  • Buat menu FORM seperti gambar diatas
  • Lalu ketikan kode dibawah ini


'
' This software / project made by Satrio Dwi Prabowo
' Application Development Professional
' CCDP TELKOM PDC KARAWANG 2015
' Copyright (c) 2015, SatrioDwiPrabowo
'
Imports System.Data.SqlClient
Public Class Form1
    Dim cnn As SqlConnection
    Dim cmmd As SqlCommand
    Dim dreder As SqlDataReader
    'Otomatis off saat startup app
    Sub off()
        TextBox1.Enabled = False
        TextBox2.Enabled = False
        TextBox3.Enabled = False
        TextBox4.Enabled = False
    End Sub
    'Otomatis on
    Sub on2()
        TextBox1.Enabled = True
        TextBox2.Enabled = True
        TextBox3.Enabled = True
        TextBox4.Enabled = True
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Button2.Focus()
        off()
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'Fix saat textbox tidak diisi
        If TextBox1.Text = "" Then
            MessageBox.Show("Harap masukan NO ID... !!!", "Konfirmasi", MessageBoxButtons.AbortRetryIgnore)
            TextBox1.Focus()
        Else
            'command menyimpan data ke database
            sql = "insert into DataPegawai (ID_PEG,NAMA,NO_TLP,ALAMAT)" & "values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
            Dim cmm As New SqlCommand(sql, Koneksi.Koneksi) 'perbedaannya
            Dim x As Integer = cmm.ExecuteNonQuery
            If x = 1 Then
                MessageBox.Show("DATA BERHASIL DISIMPAN", "XSSDP")
                TextBox1.Text = ""
                TextBox2.Text = ""
                TextBox3.Text = ""
                TextBox4.Text = ""
                TextBox1.Focus()
            Else
                MessageBox.Show("GAGAL MENYIMPAN DATA ")
            End If
        End If
    End Sub
    'Penggunaan keypress button ( Menggunakan dengan keyboard )
    Private Sub Button1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Button1.KeyPress
        sql = "insert into DataPegawai (ID_PEG,NAMA,NO_TLP,ALAMAT)" & "values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
        Dim cmm As New SqlCommand(sql, Koneksi.Koneksi)
        Dim x As Integer = cmm.ExecuteNonQuery
        If x = 1 Then
            MessageBox.Show("DATA BERHASIL DISIMPAN")
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
        Else
            MessageBox.Show("GAGAL MENYIMPAN DATA ")
        End If
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        'Mengaktifkan semua button
        on2()
        TextBox1.Focus()
    End Sub
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Me.Close()
    End Sub
End Class
Pastikan data berhasi disimpan


  • Simpan lalu coba running aplikasi sederhana yang tadi di buat :) 
  • Selamat mencoba sekian dari admin 
  • Ada pertanyaan ? silahkan tanyakan di [email protected]
Comments
0 Comments