0% found this document useful (0 votes)
30 views

Pemrograman Visual Basic Dengan SQL

1. The document discusses creating a Visual Basic program to manage a database using SQL. It involves making a database in Access called LATSQL.mdb with a table called KURSUS to store course data. 2. A form is created in Visual Basic with labels, textboxes and command buttons to insert, select, update and delete course records from the KURSUS table. 3. Programming code is provided to connect to the Access database, execute SQL queries to manipulate the course data, and refresh the form's data grid to show changes.

Uploaded by

Alam Intiyo
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Pemrograman Visual Basic Dengan SQL

1. The document discusses creating a Visual Basic program to manage a database using SQL. It involves making a database in Access called LATSQL.mdb with a table called KURSUS to store course data. 2. A form is created in Visual Basic with labels, textboxes and command buttons to insert, select, update and delete course records from the KURSUS table. 3. Programming code is provided to connect to the Access database, execute SQL queries to manipulate the course data, and refresh the form's data grid to show changes.

Uploaded by

Alam Intiyo
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Pemrograman Database VB dengan SQL

STEKOM Semarang

PEMROGRAMAN VISUAL BASIC DENGAN SQL


1. Buat folder baru bernama VBbySQL 2. Buka Microsoft Access, buat database baru dengan nama LATSQL.mdb dan simpan di folder
yang baru saja anda buat

3. Buat tabel baru bernama KURSUS dengan susunan field sebagai berikut :
Nama Field Kode_Kursus Nama_Kursus Jumlah_Jam Type Text Text Number Size 4 20 Integer

Simpan dan keluar dari Ms. Access 4. Buka Visual Basic dan pilih Standard Exe

Buat tampilan seperti berikut :

Komponen Project Form Label Label1 Label2 Label3 Label4 TextBox1 TextBox2 TextBox3 Command1 Command2 Command3 Command4 Command5 Adodc

TextBox

Command Button

Property Name Name Caption Caption Caption Caption Caption Name Name Name Name Caption Name Caption Name Caption Name Caption Name Caption Name Visible

Nilai ProVBbySQL FrmKURSUS FORM INPUT DATA KURSUS KURSUS PAKET HEMAT STEKOM KODE PAKET NAMA PAKET JUMLAH JAM Text1 untuk Kode Paket Text2 untuk Nama Paket Text3 untuk Jumlah Jam cmdInsert &Insert cmdSelect &Select cmdUpdate &Update cmdDelete &Delete cmdClose &Close Adodc1 False 1

Pemrograman Database VB dengan SQL

STEKOM Semarang

DataGrid

Name DataSource

DataGrid1 Adodc1

5. Klik Reference ( Project References )

6. Pilih/aktifkan Microsoft ActiveX Data Objects Library

7. Klik Ok 8. Ketik kode program berikut :

Dim db As ADODB.Connection Dim strcon As String

Private Sub Form_Load() Set db = New ADODB.Connection strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & _ App.Path & "\LatSQL.mdb" & "'" Adodc1.ConnectionString = strcon Adodc1.RecordSource = "Select * from KURSUS order by KODE_KURSUS" Adodc1.Refresh End Sub

Private Sub Insert_Data(str1 As String, str2 As String, str3 As Integer) Dim query As String query = "INSERT INTO KURSUS VALUES ('" & str1 & "', '" & str2 & _ "'," & str3 & ")" db.Open strcon db.Execute (query) db.Close End Sub

Private Sub cmdInsert_Click() If Text1.Text <> "" Then Call Insert_Data(Text1.Text, Text2.Text, Text3.Text) End If Text1.Text = "" Text2.Text = "" Text3.Text = "" Adodc1.Refresh End Sub

Private Sub Select_Data() Dim rs As ADODB.Recordset Dim query As String


2

Pemrograman Database VB dengan SQL

STEKOM Semarang

query = "SELECT NAMA_KURSUS,JUMLAH_JAM FROM KURSUS WHERE " & _ "KODE_KURSUS='" & Text1.Text & "'" db.Open strcon Set rs = db.Execute(query) If Not rs.EOF Then Text2.Text = rs!NAMA_KURSUS Text3.Text = rs!JUMLAH_JAM Else MsgBox "Data Tidak Ditemukan ... !", vbOKOnly, "Perhatian !" End If db.Close End Sub Private Sub cmdSelect_Click() Select_Data Adodc1.Refresh End Sub Private Sub Update_Data(str1 As Dim query As String query = "UPDATE KURSUS SET " & "NAMA_KURSUS='" & str2 "JUMLAH_JAM=" & str3 & "WHERE KODE_KURSUS ='" db.Open strcon db.Execute (query) db.Close End Sub Private Sub cmdUpdate_Click() If Text1.Text <> "" Then Call Update_Data(Text1.Text, Text2.Text, Text3.Text) End If Text1.Text = "" Text2.Text = "" Text3.Text = "" Adodc1.Refresh End Sub Private Sub Delete_Data(str1 As String) Dim rs As ADODB.Recordset Dim query As String query = "DELETE FROM KURSUS WHERE KODE_KURSUS='" & str1 & "'" db.Open strcon Set rs = db.Execute(query) db.Close End Sub Private Sub cmdDelete_Click() Dim x As String If Text1.Text <> "" Then x = MsgBox("Data ini yakin untuk dihapus ?", vbYesNo, "Hapus") If x = vbYes Then Call Delete_Data(Text1.Text) End If End If Text1.Text = "" Text2.Text = "" Text3.Text = "" Adodc1.Refresh End Sub Private Sub cmdClose_Click() Unload Me End Sub
3

String, str2 As String, str3 As Integer) _ & "'," & _ " " & _ & str1 & "'"

Pemrograman Database VB dengan SQL

STEKOM Semarang

You might also like