FORM TAMBAH, SIMPAN, HAPUS PADA VB.NET - MS.ACCES

Tanpa Basa-basi ( bngung mau ngmng ap) langsung saja buat database di ms.acces dg field


FIELD
FORMAT
SIZE
KD_BRG
TEXT
30
NM_BRG
TEXT
30
JUMLAH
NUMBER
LONG
SATUAN
TEXT
15


 Kemudian Desai form seperti Berikut :




Dan atur properties nya sebagai berikut :




Index
NAMA
TEXT
LABEL1

KODE BARANG
LABEL2

NAMA BARANG
LABEL3

WARNA
LABEL4

JUMLAH
LABEL5

SATUAN
TEXTBOX1
TXTKODE

TEXTBOX2
TXTNAMA

TEXTBOX3
TXTWARNA

TEXTBOX4
TXTSAT

COMBOBOX1
CMBSAT

BUTTON1
BTNTAMBAH
TAMBAH
BUTTON2
BTNSIMPAN
SIMPAN
BUTTON3
BTNEDIT
EDIT
BUTTON4
BTNBATAL
BATAL
BUTTON5
BTNHAPUS
HAPUS
BUTTON6
BTNKELUAR
KELUAR
DATAGRIDVIEW1
DATAGRIDVIEW1





Atur koneksi nya sperti pada pada postingan ini stelah itu ketikkan kode berikut :

Imports System.Data.OleDb

Public Class Form1

    Private Sub KONEKSI()
        Using CONN As New OleDbConnection(My.Settings.CONNstr)
            Using ADP As New OleDbDataAdapter("SELECT*FROM TB_BRG", CONN)
                CONN.Open()
                Dim TABLE As New DataTable
                ADP.Fill(TABLE)
                DataGridView1.DataSource = TABLE
            End Using
        End Using
    End Sub

    Sub KOSONG()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        ComboBox1.Text = ""
    End Sub

    Sub AKTIF()
        TextBox1.Enabled = True
        TextBox2.Enabled = True
        TextBox3.Enabled = True
        TextBox4.Enabled = True
        ComboBox1.Enabled = True
    End Sub

    Sub NONAKTIF()
        TextBox1.Enabled = False
        TextBox2.Enabled = False
        TextBox3.Enabled = False
        TextBox4.Enabled = False
        ComboBox1.Enabled = False
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        KONEKSI()
        NONAKTIF()
        KOSONG()
        Button1.Enabled = True
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False
        Button5.Enabled = False
        Button6.Enabled = False
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button1.Enabled = False
        Button2.Enabled = True
        Button3.Enabled = True
        Button4.Enabled = True
        Button5.Enabled = True
        Button6.Enabled = True
        TextBox1.Focus()
        KOSONG()
        AKTIF()
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim pesan As String
        pesan = MsgBox("Keluar?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "penting")
        If pesan = vbYes Then
            Close()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'MEMASUKKAN DATA KEDALAM TABEL
        Dim simpan As String = "insert into tb_brg values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & ComboBox1.Text & "')"
        Try
            Using conn As New OleDbConnection(My.Settings.CONNstr)
                Using cmd As New OleDbCommand(simpan, conn)
                    conn.Open()
                    cmd.ExecuteNonQuery()
                    MsgBox("Data sudah Disimpan...", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "penting")
                    KONEKSI() 'SUB KONEKSI... UNTUK MEMANGGIL KEMBALI KONEKSI, REFRESS
                    KOSONG()
                    NONAKTIF()
                    Button1.Enabled = True
                    Button2.Enabled = False
                    Button3.Enabled = False
                    Button4.Enabled = False
                    Button5.Enabled = False
                    Button6.Enabled = True
                End Using
            End Using
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim hapus As String = "delete from tb_brg where kd_brg = '" & TextBox1.Text & "'"
        Try
            Using conn As New OleDbConnection(My.Settings.CONNstr)
                Using cmd As New OleDbCommand(hapus, conn)
                    conn.Open()
                    cmd.ExecuteNonQuery()
                    MsgBox("Data sudah Dihapus...", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "penting")
                    KONEKSI()
                    KOSONG()
                    NONAKTIF()
                    Button1.Enabled = True
                    Button2.Enabled = False
                    Button3.Enabled = False
                    Button4.Enabled = False
                    Button5.Enabled = False
                    Button6.Enabled = True
                End Using
            End Using
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim updet As String = "update tb_brg set nm_brg = '" & TextBox2.Text & "'," & _
                                                " warna = '" & TextBox3.Text & "'," & _
                                                " jumlah ='" & TextBox4.Text & "'," & _
                                                "satuan ='" & ComboBox1.Text & "'" & _
                                                "where kd_brg = '" & TextBox1.Text & "'"
        Try
            Using conn As New OleDbConnection(My.Settings.CONNstr)
                Using cmd As New OleDbCommand(updet, conn)
                    conn.Open()
                    cmd.ExecuteNonQuery()
                    MsgBox("Data sudah d update ...", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "penting ")
                    KONEKSI()
                    NONAKTIF()
                    KOSONG()
                    Button1.Enabled = True
                    Button2.Enabled = False
                    Button3.Enabled = False
                    Button4.Enabled = False
                    Button5.Enabled = False
                    Button6.Enabled = True
                End Using
            End Using
        Catch ex As Exception
            MsgBox(ex.Message)

        End Try
    End Sub

    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim ubah As Integer = Nothing
        ubah = DataGridView1.CurrentRow.Index
        With DataGridView1
            TextBox1.Text = .Item(0, ubah).Value
            TextBox2.Text = .Item(1, ubah).Value
            TextBox3.Text = .Item(2, ubah).Value
            TextBox4.Text = .Item(3, ubah).Value
            ComboBox1.Text = .Item(4, ubah).Value
        End With
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        KONEKSI()
        Call KOSONG()
        Call NONAKTIF()
        Button1.Enabled = True
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False
        Button5.Enabled = False
        Button6.Enabled = True
    End Sub

End Class

Terimakasih telah membaca artikel saya yang masih banyak kekurangan ini, mohon maaf dengan banyaknya kekurangan ini

semoga tetap bermanfaat,
jika ada pertanyaan silahkan tulis di komentar


Comments

  1. mf bru Onlen,,, cb ntar saya cari dl

    ReplyDelete
  2. terima kasih banyak sob, ilmunya sangat bermanfaat ^_^

    ReplyDelete
  3. gan kirim file jadi lewat email ahmadfadilah94@gmail.com

    ReplyDelete
  4. mantap gan ane coba langsung sukse maksih gan ilmunya, o iya untuk pencarian data giman gan skripnya

    ReplyDelete
  5. gan kirim ke elyas6000m@gmail.com gan

    ReplyDelete
  6. gan kirim ke elyas6000m@gmail.com gan

    ReplyDelete

Post a Comment

Popular Posts