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

Sqlconnection Sqldataadapter Sqldatareader Dataset Sqlcommand Sqlconnection

The document describes a database called dbretail with a table called tblbarang, and a Visual Basic .NET project called prjretail with a form called frmbarang for managing product data. The form allows users to view, add, edit, delete and search product records in the database table, with controls for inputting and displaying product code, name, unit, and stock quantities. The form code includes procedures for connecting to the database, refreshing the data grid view, validating data entry, and executing CRUD operations on the product records.

Uploaded by

taupanbritish123
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)
44 views3 pages

Sqlconnection Sqldataadapter Sqldatareader Dataset Sqlcommand Sqlconnection

The document describes a database called dbretail with a table called tblbarang, and a Visual Basic .NET project called prjretail with a form called frmbarang for managing product data. The form allows users to view, add, edit, delete and search product records in the database table, with controls for inputting and displaying product code, name, unit, and stock quantities. The form code includes procedures for connecting to the database, refreshing the data grid view, validating data entry, and executing CRUD operations on the product records.

Uploaded by

taupanbritish123
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
You are on page 1/ 3

Database : dbretail

Tabel 1 : tblbarang

Nama Project : prjretail


Module 1 : Modul1
Imports System.Data.SqlClient
Module Module1
Public CON As SqlConnection
Public DA As SqlDataAdapter
Public DR As SqlDataReader
Public DS As DataSet
Public CMD As SqlCommand
Public CN As New SqlClient.SqlConnection
Public KONEKSI As String

Sub BUKAKONEKSI()
KONEKSI = "server=.\sqlexpress;database=dbretail;user id=;password=;integrated security=true"
CN = New SqlClient.SqlConnection(KONEKSI)
Try
CN.Open()
MessageBox.Show(" KONEKSI BERHASIL ")
Catch ex As Exception
MessageBox.Show(ex.Message, "Error")
End
End Try
End Sub
End Module

Form1 : frmbarang

No Noma Objek Properties Nilai Attribute No Noma Objek Properties Nilai Attribute
1 Label1 text KODE 8 Textbox3 name txtstok
2 Label2 text NAMA 9 Button1 name btnsimpan
text SIMPAN
3 Label3 text STOK 10 Button1 name btnubah
text UBAH
4 Label4 text Satuan 11 Button1 name btnhapus
text HAPUS
5 Textbox1 name txtkode 12 Button1 name btnkeluar
text KELUAR
6 Textbox2 name txtnama 13 DatagridViews1 name btncari
7 Combobox1 name cmbsatuan 14 Form1 name frmbarang
Items UNIT text FORM BARANG
LUSIN
PCX
BUAH

Imports System.Data.SqlClient
Public Class frmbarang
Private Sub frmbarang_Load(sender As Object, e As EventArgs) Handles Me.Load
BUKAKONEKSI()
On Error GoTo salah
CON = New SqlConnection(KONEKSI)
If CON.State = ConnectionState.Closed Then
CON.Open()
End If
Call refreshtampil()
Exit Sub
salah:
MsgBox(Err.Description)
End
End Sub

Sub refreshtampil()
DA = New SqlDataAdapter("SELECT * FROM tblbarang", CON)
DS = New DataSet
DS.Clear()
DA.Fill(DS, “tblbarang")
dgvtampil.DataSource = (DS.Tables(“tblbarang"))
End Sub

Sub bersihkan_form()
txtkode.Text = ""
txtnama.Text = ""
cmbsatuan.Text = ""
txtstok.Text = ""
txtkode.Focus()
End Sub

Private Sub btnsimpan_Click(sender As Object, e As EventArgs) Handles btnsimpan.Click


Dim sql As String
CMD = New SqlCommand("SELECT * FROM tblbarang WHERE kode_brg= '" & txtkode.Text & "'", CON)
DR = CMD.ExecuteReader
If DR.Read Then
MsgBox("DATA SUDAH ADA", vbInformation, "PERINGATAN")
Call bersihkan_form()
Else
DR.Close()
sql = "INSERT INTO tblbarang
VALUES( '" & txtkode.Text & "',
'" & txtnama.Text & "',
'" & cmbsatuan.Text & "',
'" & txtstok.Text & "')"
CMD = New SqlCommand(sql, CON)
CMD.ExecuteNonQuery()
Call refreshtampil()
Call bersihkan_form()
MsgBox("DATA BERHASIL DISIMPAN", vbInformation, "KONFIRMASI")
End If
DR.Close()
End Sub

Private Sub btncari_Click(sender As Object, e As EventArgs) Handles btncari.Click


Dim cari As String
cari = InputBox("Masukkan KODE BARANG : ", "PENCARIAN")
CMD = New SqlCommand("SELECT * FROM tblbarang WHERE kode_brg= '" & cari & "'", CON)
DR = CMD.ExecuteReader
If DR.Read Then
txtkode.Text = DR.Item("kode_brg")
txtnama.Text = DR.Item("nama_brg")
cmbsatuan.Text = DR.Item(“satuan")
txtstok.Text = DR.Item("stok")
Else
MsgBox("DATA TIDAK DITEMUKAN", vbInformation, "PERINGATAN")
End If
DR.Close()
End Sub

Private Sub btnhapus_Click(sender As Object, e As EventArgs) Handles btnhapus.Click


Dim sql As String
Dim PSN As String
PSN = MsgBox("APAKAH YAKIN DIHAPUS?", vbQuestion + vbYesNo, "KONFIRMASI")
If PSN = vbYes Then
sql = "DELETE FROM tblbarang WHERE kode_brg= '" & txtkode.Text & "'"
CMD = New SqlCommand(sql, CON)
Dim x As Integer = CMD.ExecuteNonQuery
If x = 1 Then
Call refreshtampil()
Call bersihkan_form()
MsgBox("DATA BERHASIL DIHAPUS", vbInformation, "KONFIRMASI")
Else
MsgBox("GAGAL HAPUS DATA", vbInformation, "PERINGATAN")
End If
End If
End Sub

Private Sub btnubah_Click(sender As Object, e As EventArgs) Handles btnubah.Click


Dim sql As String
sql = "UPDATE tblbarang SET nama_brg=" &
"'" & txtnama.Text & "',satuan='" & cmbsatuan.Text & "',stok='" & txtstok.Text & "' WHERE
kode_brg= '" & txtkode.Text & "'"
CMD = New SqlCommand(sql, CON)
CMD.ExecuteNonQuery()
Call refreshtampil()
Call bersihkan_form()
MsgBox("DATA BERHASIL DIUPDATE", vbInformation, "KONFIRMASI")
End Sub

Private Sub btnkeluar_Click(sender As Object, e As EventArgs) Handles btnkeluar.Click


Dim keluar As String
keluar = MsgBox("APAKAH ANDA INGIN KELUAR DARI APLIKASI?", vbQuestion + vbYesNo,
"KONFIRMASI")
If keluar = vbYes Then
Dispose()
End If
End Sub

End Class

You might also like