0% found this document useful (0 votes)
32 views3 pages

Sistem CRUD Stok Barang PHP MySQL

This document contains the source code for a Visual Basic .NET application. The code defines classes and subroutines to connect to a MySQL database, retrieve and display data in a datagrid, and allow the user to add, update, and delete records. Key features include connecting to the database, filling a dataset and binding it to the datagrid, and handling button clicks to perform CRUD operations by executing SQL commands.

Uploaded by

Dheyat
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views3 pages

Sistem CRUD Stok Barang PHP MySQL

This document contains the source code for a Visual Basic .NET application. The code defines classes and subroutines to connect to a MySQL database, retrieve and display data in a datagrid, and allow the user to add, update, and delete records. Key features include connecting to the database, filling a dataset and binding it to the datagrid, and handling button clicks to perform CRUD operations by executing SQL commands.

Uploaded by

Dheyat
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NAMA : RAHMAT HIDAYAT

NIM : 1815025091
KELAS : ILKOM B 2018
MATKUL PRAKTIKUM : REKAYASA PERANGKAT LUNAK B2

Source Code

Imports [Link]
Public Class Form1
Dim Conn As OdbcConnection
Dim Cmd As OdbcCommand
Dim Ds As DataSet
Dim Da As OdbcDataAdapter
Dim Rd As OdbcDataReader
Dim MyDB As String

*Koneksi Data

Sub Koneksi()
MyDB = "Driver={MySQL ODBC 3.51 Driver};Database=db_distro;Server=Localhost;uid=root"
Conn = New OdbcConnection(MyDB)
If [Link] = [Link] Then [Link]()
End Sub

Private Sub Form1_Load(ByVal sender As [Link], ByVal e As [Link]) Handles


[Link]
Call KondisiAwal()
End Sub

*Sub Tampil Data

Sub KondisiAwal()
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = "Tambah Data"
[Link] = "Ubah Data"
[Link] = "Hapus Data"
[Link] = "Cari"
[Link] = "Exit"
Call Koneksi()
Da = New OdbcDataAdapter("Select * From tb_barang", Conn)
Ds = New DataSet
[Link](Ds, "tb_barang")
[Link] = [Link]("tb_barang")

End Sub
*Button 1

Private Sub Button1_Click(ByVal sender As Object, e As EventArgs) Handles [Link]


If [Link] = "" Or [Link] = "" Or [Link] = "" Or [Link] = "" Or
[Link] = "" Or [Link] = "" Or [Link] = "" Or [Link] = "" Then
MsgBox("Pastikan semua field terisi ")
Else
Call Koneksi()
Dim TambahData As String = "Insert into tb_barang values ('" & [Link] & "','" &
[Link] & "','" & [Link] & "','" & [Link] & "','" & [Link] & "','" &
[Link] & "','" & [Link] & "','" & [Link] & "')"
Cmd = New OdbcCommand(TambahData, Conn)
[Link]()
MsgBox("Tambah Data Berhasil")
Call KondisiAwal()
End If
End Sub

*Button 2

Private Sub Button2_Click(ByVal sender As Object, e As EventArgs) Handles [Link]


If [Link] = "" Or [Link] = "" Or [Link] = "" Or [Link] = "" Or
[Link] = "" Or [Link] = "" Or [Link] = "" Or [Link] = "" Then
MsgBox("Pastikan semua field terisi ")
Else
Call Koneksi()
Dim UbahData As String = "Update tb_barang set Nama='" & [Link] & "',TTL='" &
[Link] & "',Tempat Lahir ='" & [Link] & "',No Telepon='" & [Link] & "' ,Barang='"
& [Link] & "' ,Harga Barang='" & [Link] & "',Alamat= '" & [Link] & "' where ID = '"
& [Link] & "'"
Cmd = New OdbcCommand(UbahData, Conn)
[Link]()
MsgBox("Ubah Data Berhasil")
Call KondisiAwal()
End If
End Sub

*Button 3

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles [Link]


If [Link] = "" Or [Link] = "" Or [Link] = "" Or [Link] = "" Or
[Link] = "" Or [Link] = "" Or [Link] = "" Or [Link] = "" Then
MsgBox("Pastikan Data yang Akan Dihapus Terisi ")
Else
Call Koneksi()
Dim HapusData As String = "Delete from tb_barang where ID='" & [Link] & "'"
Cmd = New OdbcCommand(HapusData, Conn)
[Link]()
MsgBox("Hapus Data Berhasil")
Call KondisiAwal()
End If
End Sub

*Button 4

Private Sub Button4_Click(ByVal sender As Object, e As EventArgs) Handles [Link]


Call Koneksi()
Cmd = New OdbcCommand("Select * from tb_barang where nama Like '%" & [Link] & "%'",
Conn)
Rd = [Link]
[Link]()
If [Link] Then
Call Koneksi()
Da = New OdbcDataAdapter("Select * from tb_barang where nama Like '%" & [Link] & "%'",
Conn)
Ds = New DataSet
[Link](Ds, "Data Ketemu")
[Link] = [Link]("Data Ketemu")
[Link] = True
End If
End Sub

*TextBox 1

Private Sub TextBox1_KeyPress(ByVal sender As Object, e As [Link])


Handles [Link]
If [Link] = Chr(13) Then
Call Koneksi()
Cmd = New OdbcCommand("Select * From tb_barang where ID ='" & [Link] & "'", Conn)
Rd = [Link]
[Link]()
If [Link] Then
[Link] = [Link]("Nama")
[Link] = [Link]("TTL")
[Link] = [Link]("Tempat Lahir")
[Link] = [Link]("No Telepon")
[Link] = [Link]("Barang")
[Link] = [Link]("Harga Barang")
[Link] = [Link]("Alamat")

Else
MsgBox("Data Tidak Ada")
End If
End If
End Sub

You might also like