0% found this document useful (0 votes)
34 views4 pages

Tutorial Praktikum 2rpl

This document provides instructions for creating a database table named "tbl_kategori" and connecting it to a form interface in Visual Basic. It includes code snippets for: 1. Connecting to the database and opening the connection 2. Populating a datagridview from a SQL query on the "tbl_kategori" table 3. Retrieving selected row data and filling textboxes when a row is clicked 4. Code for input, update, delete and clear buttons to manage the table data

Uploaded by

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

Tutorial Praktikum 2rpl

This document provides instructions for creating a database table named "tbl_kategori" and connecting it to a form interface in Visual Basic. It includes code snippets for: 1. Connecting to the database and opening the connection 2. Populating a datagridview from a SQL query on the "tbl_kategori" table 3. Retrieving selected row data and filling textboxes when a row is clicked 4. Code for input, update, delete and clear buttons to manage the table data

Uploaded by

yasirdean
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

ATUR DATABASE DENGAN TABEL SBB :

BERI NAMA TABEL DENGAN NAMA tbl_kategori

2. MEMBUAT FORM
Buat form seperti di bawah ini :
3. BUAT MODULE

Imports System.Data
Imports System.Data.Odbc
Imports System.Data.SqlClient

Imports MySql.Data.MySqlClient
Imports System.Data.OleDb
Module Module1
Public konek As System.Data.Odbc.OdbcConnection
Public DA As OdbcDataAdapter
Public DR As OdbcDataReader
Public DS As DataSet
Public CMD As OdbcCommand
Sub bukaDB()
Try
konek = New OdbcConnection("DSN=penjualan;MultipleActiveResultSets=True")
If konek.State = ConnectionState.Closed Then
konek.Open()
End If
Catch ex As Exception
MsgBox("konek Kedatabase Bermasalah, Periksa koneksi Jaringan Anda")
End Try
End Sub
End Module

4. LISTING DI FORM
Ketik listing ini di form dengan cara klik 2 x form sehingga seperti gambar di
bawah ini :

Imports System.Data.Odbc

Public Class Form1


Dim tabel As System.Data.Odbc.OdbcDataAdapter
Dim data As DataSet
Dim record As New BindingSource

(INGATTTT.JANGAN DIKETIK Public Class Form1.KARENA SDH OTOMATIS JI


MUNCUL)
5. LISTING PROSEDURE BERSIH
Ketik listing dibawah ini (semuanya )

Private Sub Bersih()


Dim a As Control
For Each a In Me.Controls
If TypeOf a Is TextBox Then a.Text = ""
If TypeOf a Is ComboBox Then a.Text = ""
Next
End Sub

Private Sub jalankansql(ByVal sQl As String)


Dim objcmd As New System.Data.Odbc.OdbcCommand
Call bukaDB()
Try
objcmd.Connection = konek
objcmd.CommandType = CommandType.Text
objcmd.CommandText = sQl
objcmd.ExecuteNonQuery()
objcmd.Dispose()
Catch ex As Exception
MsgBox("Tidak Bisa diproses ke Server" & ex.Message)
End Try
End Sub

Public Sub Daftar()


tabel = New System.Data.Odbc.OdbcDataAdapter("Select * from tbl_kategori order by
id_kategori", konek)
data = New DataSet
tabel.Fill(data)
record.DataSource = data
record.DataMember = data.Tables(0).ToString()
DGV.DataSource = record
BuatHeader()
End Sub

Public Sub BuatHeader()


DGV.Columns(0).HeaderText = "Kode"
DGV.Columns(1).HeaderText = "Nama Kategori"
DGV.Columns(0).Width = 100
DGV.Columns(1).Width = 400
End Sub

Private Sub isiTextBox(ByVal x As Integer)


Try
txtKode.Text = DGV.Rows(x).Cells(0).Value
txtNama.Text = DGV.Rows(x).Cells(1).Value
Catch ex As Exception
End Try
End Sub

6. LISTING TOMBOL INPUT

Bersih()
txtKode.Focus()

7. LISTING TOMBOL REKAM

CMD = New OdbcCommand("Select * from tbl_kategori WHERE id_kategori='" & txtKode.Text &
"'", konek)
DR = CMD.ExecuteReader
If DR.Read Then
jalankansql("update tbl_kategori set nm_kategori='" & txtNama.Text & "' where kd_kategori='" &
txtKode.Text & "'")
MsgBox("terekam mi tawwa")
Daftar()
Bersih()
txtKode.Focus()
Else
jalankansql("insert into tbl_kategori values('" & txtKode.Text & "','" & txtNama.Text & "')")
MsgBox("terekam mi tawwa")
Daftar()
Bersih()
txtKode.Focus()
End If
8. LISTING TOMBOL HAPUS

jalankansql("delete from tbl_kategori where kd_kategori='" & txtKode.Text & "'")


MsgBox("terhapus mi datanya mi tawwa")
Daftar()
Bersih()

9. LISTING DI DGV_CellClick
Klik 2x pada GRIDVIEW nya, lihat gambar di bawah ini :

ISI LISTINGNYA :

isiTextBox(e.RowIndex)
Button3.Enabled = True 'INI TOMBOL HAPUS

SILAHKAN BERPRAKTIKUM.

You might also like