Selamat datang di Ari Winard blog

Berbagi ilmu akan menambah ilmu, karena air yang dialirkan maka aliran air akan deras

Di lokasi project

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Thursday, March 29, 2012

Metode koneksi VB 6 dengan SQL Server

Ada beberapa metode untuk menghubungkan Visual Basic dengan Database MS SQL Server saya akan memberikan penjelasan 2 metode diantaranya yaitu koneksi dengan menggunakan komponen DataEnvironment dan koneksi dengan menggunakan kode Program. untuk tutorial ini saya menggunakan Visual Basic 6 dan MS SQL Server 2000.

1. Koneksi menggunakan DataEnvironment

- Buat Project Standard EXE
- Klik menu Project | Add Data Environment, maka akan ditampilkan jendela Data Environment seperti ini :

- Untuk membangun koneksi dengan Database SQL Server, Klik kanan objek Connection1 kemudian pilih Properties maka akan muncul jendela Data Link Properties.
- Pada jendela Data Link Properties pilih driver untuk koneksi ke MS SQL Server, yaitu Microsoft OLE DB Provider for SQL Server. kemudian klik Next.
- Isi dengan nama server MS SQL Server kamu pada textbox "Select or enter a server name" (nama server adalah nama komputer kamu).
- Pilih radio button "use a specific username and password" pada bagian 2.Enter information to log on to the server.
- Pada textbox username dan password isi dengan username dan password yang terdaftar di Database SQL Server kamu misalnya "sa" (user sa defaultnya tidak memiliki password). pada contoh ini saya menggunakan username 'yanadoe' dengan password 'bebas'.
- Sebagai tambahan, user sa adalah user yang mempunyai kewenangan penuh terhadap system di MS SQL Server atau disebut system administrator. user ini dibuat secara otomatis oleh MS SQL Server ketika proses instalasi.
- Setelah kamu lakukan langkah diatas, centang Checkbox "Allow saving password" agar kamu tidak perlu menginputkan lagi username dan password setiap kali aplikasi akan dijalankan.
- Pilih database Northwind pada textbox "Select the database on the server". klik tombol Test Connection untuk mengetahui apakah koneksi sudah berhasil atau tidak jika sukses klik tombol OK untuk menutup window dialog Data Link Properties
Setelah tahap diatas, koneksi dari Visual Basic ke Database MS SQL Server sudah terbentuk selanjutnya untuk mengambil data dari sebuah table di Database pertama kamu harus menambahkan sebuah Command pada DataEnvironment, Caranya sebagai berikut :
2. Mengambil Data dari Database
- Klik kanan pada jendela DataEnvironment, pilih Add Command. maka akan dibuat sebuah object dengan nama Command1.
- Klik kanan Command1, pilih Properties. setelah muncul jendela Command1 Properties, pilih Table pada bagian Database Object, dan pilih sebuah table pada bagian Object Name misalnya table Customers. kemudian klik OK.
Menampilkan Data dengan DataGrid
- Pertama kamu harus menambahkan komponen DataGrid pada ToolBox caranya : klik menu Project | Components, pada jendela Components pilih Microsoft DataGrid Control 6.0
- Setelah objek DataGrid ditambahkan pada Toolbox, klik komponen DataGrid tersebut kemudian Click and Drag pada Form1.
- Set Properties DataSource menjadi DataEnvironment1, dan Properties DataMember menjadi Command1.
- Klik kanan pada DataGrid, pilih Retrieve Fields klik OK pada Message Dialog yang muncul.
- Data pada table tidak akan langsung ditampilkan pada saat Design, untuk melihat datanya kamu harus Run Program dengan menekan F5.

Wednesday, March 7, 2012

Aplikasi Database Menggunakan SQL Statement pada Visual Basic 6

Pada tutorial kali ini saya akan menjelaskan bagaimana cara memanipulasi data menggunakan SQL Statement di Visual Basic. Tujuan tutorial ini adalah agar pembaca bisa memahami bagaimana cara menggunakan SQL Statement untuk memanipulasi data di Visual Basic oleh karena itu tutorial ini dibuat se-jelas dan se-sederhana mungkin tetapi tidak mengesampingkan pemahaman pokok tentang operasi DML dengan SQL Statement.
Buat sebuah File Database menggunakan Microsoft Access, simpan di c:\Sample dengan nama DBSample.mdb
Buat sebuah table dengan nama Products dengan struktur sebagai berikut :

ProductID Text(20)
Description Text(50)
Price number(Double)

Masuk ke Visual Basic, buat sebuah project Standard.EXE simpan di c:\Sample dengan nama SQLDML.vbp

Tambahkan tiga buah Textbox : txtPid, txtDesc, dan txtPrice
Tambahkan tiga buah Label : lblPid, lblDesc, dan lblPrice
Tambahkan tiga buah Button : cmdSave, cmdUpdate, cmdDelete, cmdSearch
Tambahkan lagi empat buah button untuk navigasi record : cmdFirst, cmdPrev, cmdNext, cmdLast


Koneksi dengan Database MS Access

Masuk code editor, deklarasikan dua buah variabel untuk koneksi Database dan Recordset

Dim AccessConn As New ADODB.Connection
Dim rsProduct As New ADODB.Recordset
Dobel klik Form1, tambahkan kode program berikut :
Set AccessConn = New ADODB.Connection
AccessConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\DBSample.mdb;Persist Security Info=False"
'kode program App.Path akan menghasilkan path dari file .exe aplikasi ini
'yaitu C:\Sample
'buka koneksi
AccessConn.Open
SQLStr = "select * from products"
Set rsProduct = New ADODB.Recordset
rsProduct.Open SQLStr, AccessConn, adOpenDynamic, adLockOptimistic, adCmdText

Menambah Data dengan SQL Insert Statement

Dobel klik button cmdSave, tambahkan kode program berikut :

Dim SQLStr As String
'deklarasi variabel SQLStr
'yang nantinya akan digunakan untuk perintah SQL
SQLStr = "insert into products (productid,description,price) " & _
"values('" & txtPid & "','" & txtDesc & "','" & txtPrice & "')"
'Execute SQL Command
AccessConn.Execute SQLStr, , cmdtypetext
'tampilkan pesan
MsgBox "Data telah tersimpan", vbInformation, "Informasi"
'refresh dataset rsproduct agar record baru langsung terlihat
rsProduct.Requery
'clear textbox
txtPid = ""
txtDesc = ""
txtPrice = ""
txtPid.SetFocus


Mencari Data dengan SQL Select Statement

Karena SQL Select Statement menghasilkan/mengembalikan satu atau lebih record maka perlu dideklarasikan sebuah variabel recordset baru yaitu rsproductsCari untuk menampung recordset hasil query pencarian

Dobel klik button cmdSearch, tambahkan kode Program berikut :

Dim SQLStr As String
Dim rsproductsCari As New ADODB.Recordset
'mencari product berdasarkan productid
SQLStr = "select * from products where productid = '" & txtPid & "'"
Set rsproductsCari = New ADODB.Recordset
rsproductsCari.Open SQLStr, AccessConn, adOpenDynamic, adLockOptimistic, adCmdText
If Not rsproductsCari.BOF And Not rsproductsCari.EOF Then
'jika data ada, tampilkan record pada textbox
txtPid = rsproductsCari!productid
txtDesc = rsproductsCari!Description
txtPrice = rsproductsCari!price
Else
'jika tidak ada, tampilkan pesan
MsgBox "Data tidak ditemukan", vbInformation, "Informasi"
'clear textbox
txtPid = ""
txtDesc = ""
txtPrice = ""
txtPid.SetFocus
End If


Mengedit Data dengan SQL Update Statement

Dobel klik button cmdUpdate, tambahkan kode Program berikut :

Dim SQLStr As String
SQLStr = "update products set description='" & txtDesc & "'," & _
"price='" & txtPrice & "' where productid='" & txtPid & "'"
Set rsProduct = AccessConn.Execute(SQLStr, , cmdtypetext)
'refresh dataset rsproduct agar record baru langsung terlihat
rsProduct.Requery
'tampilkan pesan
MsgBox "Perubahan telah tersimpan", vbInformation, "Informasi"
'clear textbox
txtPid = ""
txtDesc = ""
txtPrice = ""
txtPid.SetFocus


Menghapus Data dengan SQL Delete Statement

Dobel klik button cmdDelete, tambahkan kode Program berikut :

Dim SQLStr As String
Dim msgresult As Byte
'deklarasi variabel msgresult
'digunakan untuk menangkap result dari pesan konfirmasi delete
msgresult = MsgBox("Hapus Data produk " & txtPid, vbYesNo + vbQuestion, "Confirm")
If msgresult = vbYes Then
SQLStr = "delete from products where productid='" & txtPid & "'"
Set rsProduct = AccessConn.Execute(SQLStr, , cmdtypetext)
'refresh dataset rsproduct agar record baru langsung terlihat
rsProduct.Requery
'clear textbox
txtPid = ""
txtDesc = ""
txtPrice = ""
txtPid.SetFocus
End If


Navigasi Record Dengan Kode Program

Ini adalah kode Program untuk navigasi record ke posisi record pertama.

Dobel klik button cmdFirst, tambahkan kode Program berikut :

On Error Resume Next
rsProduct.MoveFirst
'menampilkan data
txtPid = rsProduct!productid
txtDesc = rsProduct!Description
txtPrice = rsProduct!price

Kode Program untuk navigasi record ke posisi record sebelumnya. jika record sudah di posisi record pertama, maka pointer tetap akan diarahkan ke record pertama. kamu bisa ganti kode Program rsproduct.MoveFirst dengan rsproduct.MoveLast agar navigasi kembali ke record terakhir setelah berada pada record pertama.

Dobel klik button cmdPrev, tambahkan kode Program berikut :

On Error Resume Next
rsProduct.MovePrevious
If rsProduct.BOF Then
rsProduct.MoveFirst
End If
'menampilkan data
txtPid = rsProduct!productid
txtDesc = rsProduct!Description
txtPrice = rsProduct!price

Kode Program untuk navigasi record ke posisi record berikutnya. jika record sudah di posisi record terakhir, maka pointer tetap akan diarahkan ke record terakhir. kamu bisa ganti kode Program rsproduct.MoveLast dengan rsproduct.MoveFirst agar navigasi kembali ke record pertama setelah berada pada record terakhir.

Dobel klik button cmdNext, tambahkan kode Program berikut :

On Error Resume Next
rsProduct.MoveNext
If rsProduct.EOF Then
rsProduct.MoveLast
End If
'menampilkan data
txtPid = rsProduct!productid
txtDesc = rsProduct!Description
txtPrice = rsProduct!price

Kode Program untuk navigasi record ke posisi record terakhir.

Dobel klik button cmdLast, tambahkan kode Program berikut :

On Error Resume Next
rsProduct.MoveLast
'menampilkan data
txtPid = rsProduct!productid
txtDesc = rsProduct!Description
txtPrice = rsProduct!price









Tuesday, March 6, 2012

Introduction to Visual Basic 6

1.1 The concept of computer programming
Before we begin Visual Basic 6 programming, let us understand some basic concepts of programming. According to Webopedia, a computer program is an organized list of instructions that, when executed, causes the computer to behave in a predetermined manner. Without programs, computers are useless. Therefore, programming means designing or creating a set of instructions to ask the computer to carry out certain jobs which normally are very much faster than human beings can do.