You are on page 1of 8

TUGAS 5

PROGRAM DAN APLIKASI KOMPUTER

Database Rumah Makan

Oleh

Sanjaya 03021281520134

UNIVERSITAS SRIWIJAYA
FAKULTAS TEKNIK
JURUSAN TEKNIK PERTAMBANGAN
2017
Coding pada Form
Imports System.Data.SqlClient
Imports System.Data
Public Class Form1

Public koneksi As String


Public sql1, sql2, sql3 As String
Public conn As SqlClient.SqlConnection = Nothing
Public cmd As SqlClient.SqlCommand = Nothing
Public dtadapter As New SqlClient.SqlDataAdapter
Public dttable As New DataTable
Dim Penjualan_Makanan As Object

Private Property Catalog As Object

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles


Button1.Click
Bersih()
MsgBox("Data Baru", MsgBoxStyle.Information, "Perhatian")
End Sub

Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles


Button4.Click
End
End Sub

Private Sub DataGridView1_CellContentClick(sender As System.Object, e As


System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

End Sub

Private Sub Form1_load(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles MyBase.Load
'PERINTAH KONEKSI DATABASE DISIMPAN 1 BARIS
koneksi = "Data Source=localhost\sqlexpress;Initial Catalog =
master;Integrated Security=True"
conn = New SqlClient.SqlConnection(koneksi)
conn.Open()
End Sub
Sub Bersih()
Me.TextBox1.Focus()
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
Me.TextBox3.Text = ""
Me.TextBox4.Text = ""
End Sub
Sub Simpan()
sql1 = "Insert into Makanan values('" &
Me.TextBox1.Text & "','" & Me.TextBox2.Text & "','" &
Me.TextBox3.Text & "','" & Me.TextBox4.Text & "')"
cmd = New SqlClient.SqlCommand(sql1)
cmd.Connection = conn
cmd.ExecuteNonQuery()
End Sub
Sub daftar()
sql2 = "select * from Makanan"
dtadapter = New SqlDataAdapter(sql2, conn) 'dibuat satu baris
Dim BRG As New DataTable
BRG.Clear()
dtadapter.Fill(BRG)
DataGridView1.DataSource = BRG
End Sub

Private Sub Button2_Click_1(sender As System.Object, e As System.EventArgs)


Handles Button2.Click
Simpan()
daftar()
Bersih()
MsgBox("Data Sudah Disimpan", MsgBoxStyle.Information,
"Perhatian")
End Sub

Private Sub Button3_Click_1(sender As System.Object, e As System.EventArgs)


Handles Button3.Click
Bersih()
MsgBox("Data Sudah digagalkan", MsgBoxStyle.Information,
"Perhatian")
End Sub

Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles


Button5.Click
cari()
End Sub
Sub cari()
Dim cari As String
cari = InputBox("Masukan Kode Makanan", "Pencarian")
sql3 = "select * from Makanan where Kode_Makanan = '" &
cari & "'"
dtadapter = New SqlDataAdapter(sql3, conn) 'dibuat satu baris
Dim BRG As New DataTable
BRG.Clear()
dtadapter.Fill(BRG)
DataGridView1.DataSource = BRG
End Sub
End Class

You might also like