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

Panduan Membuat Form Database ODBC

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)
42 views4 pages

Panduan Membuat Form Database ODBC

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

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 [Link]
Imports [Link]
Imports [Link]

Imports [Link]
Imports [Link]
Module Module1
Public konek As [Link]
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 [Link] = [Link] Then
[Link]()
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 [Link]

Public Class Form1


Dim tabel As [Link]
Dim data As DataSet
Dim record As New BindingSource

([Link] DIKETIK Public Class [Link] SDH OTOMATIS JI


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

Private Sub Bersih()


Dim a As Control
For Each a In [Link]
If TypeOf a Is TextBox Then [Link] = ""
If TypeOf a Is ComboBox Then [Link] = ""
Next
End Sub

Private Sub jalankansql(ByVal sQl As String)


Dim objcmd As New [Link]
Call bukaDB()
Try
[Link] = konek
[Link] = [Link]
[Link] = sQl
[Link]()
[Link]()
Catch ex As Exception
MsgBox("Tidak Bisa diproses ke Server" & [Link])
End Try
End Sub

Public Sub Daftar()


tabel = New [Link]("Select * from tbl_kategori order by
id_kategori", konek)
data = New DataSet
[Link](data)
[Link] = data
[Link] = [Link](0).ToString()
[Link] = record
BuatHeader()
End Sub

Public Sub BuatHeader()


[Link](0).HeaderText = "Kode"
[Link](1).HeaderText = "Nama Kategori"
[Link](0).Width = 100
[Link](1).Width = 400
End Sub

Private Sub isiTextBox(ByVal x As Integer)


Try
[Link] = [Link](x).Cells(0).Value
[Link] = [Link](x).Cells(1).Value
Catch ex As Exception
End Try
End Sub

6. LISTING TOMBOL INPUT

Bersih()
[Link]()

7. LISTING TOMBOL REKAM

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

jalankansql("delete from tbl_kategori where kd_kategori='" & [Link] & "'")


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([Link])
[Link] = True 'INI TOMBOL HAPUS

SILAHKAN BERPRAKTIKUM.

You might also like