1 / 16

ADODC

ADODC. Karakteristik Tipe Koneksi Adodc. Merupakan salah satu komponen ADO yang menghubungkan antara Visual Basic dengan Database. Adodc merupakan perwakilan sebuah recordset atau hasil sebuah query di dalam Visual Basic.

ludlow
Download Presentation

ADODC

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ADODC

  2. Karakteristik Tipe Koneksi Adodc • Merupakan salah satu komponen ADO yang menghubungkan antara Visual Basic dengan Database. • Adodc merupakan perwakilan sebuah recordset atau hasil sebuah query di dalam Visual Basic. • Jika menggunakan “Data Manipulation Language” pada SQL, Adodc hanya dapat digunakan untuk query “Select”. • Tidak cocok untuk data dalam jumlah besar, khususnya ketika menggunakan perintah “Select”. • Menggunakan objek berupa kontrol data (Microsoft Ado Data Control) yang merupakan komponen dari msadodc.ocx. • Untuk menampilkan data hasil query dari Adodc, dapat menggunakan komponen Datagrid (Microsoft DataGrid Control).

  3. Menambahkan Adodc & DataGrid • Tambah komponen Microsoft Ado Data Control & Microsoft DataGrid Control ke dalam Toolbox, caranya : • Tekan Ctrl + T atau pilih menu Project, lalu klik components • Untuk menambahkan komponen Adodc, cari komponen “Microsoft Ado Data Control …”. Klik tanda “check” disamping nama komponen, lalu klik ok. • Untuk menambahkan komponen DataGrid, cari komponen “Microsoft DataGrid Control …”. Klik tanda “check” disamping nama komponen, lalu klik ok • Klik dan drag komponen Adodc dan DataGrid ke dalam form untuk menggunakan kedua komponen tersebut

  4. Setting Adodc • Klik kanan kontrol Adodc, lalu pilih Adodc properties • Pilih “Use Connection String” untuk menghubungkan Adodc ke database, lalu klik build

  5. Setting Adodc • Untuk koneksi ke Microsoft Access, double click “Microsoft Jet 4.0 OLE DB Provider” atau click tombol “Next >>”

  6. Setting Adodc • Lalu klik tombol browse untuk mencari database Microsoft Access yang akan dihubungkan dengan Adodc, lalu klik ok.

  7. Setting Adodc • Pada tab Recordsource, ketikkan nama tabel pada textbox Command Text (SQL), lalu klik ok.

  8. Setting DataGrid • Untuk menampilkan data pada DataGrid, properties “Recordsource” pada Adodc harus telah terisi terlebih dahulu • Set DataSource pada Objek DataGrid ke Objek Adodc yang sudah di setting • Untuk langsung menampilkan semua field tabel ke datagrid, klik kanan objek DataGrid, lalu klik “Retreive Fields”

  9. Setting ADODB • Pada “Project Explorer”, klik kanan lalu pilih ADD, Module. • Atau klik pada toolbar untuk menambahkan Module pada Project Explorer.

  10. Setting ADODC dengan Program

  11. Setting Adodb • Deklarasikan Variabel untuk “Connection” pada Module yang telah ditambahkan. Deklarasikan Variabel Connection pada baris General (paling atas pada module). • Cth : Public Cn As ADODB.Connection • Buat sebuah “Function Public” atau “Sub Public” untuk membuka dan menutup koneksi.

  12. Setting Adodb • CthPerintahbukakoneksike “Database Access” : (* • Set Cn = New ADODB.Connection • Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data • Source=" & App.Path & "\Pustaka.mdb;Persist • Security Info=False" • Cn.ConnectionTimeout = 30 • Cn.CommandTimeout = 0 • Cn.CursorLocation = adUseClient • Cn.OpenApp.Path & "\Pustaka.mdb“ • ConnectionString • ConnectionStringadalahsebuah string yang digunakanuntukmenghubungkanLingkungan Visual Basic ke Database. • ConnectionTimeout (satuan = detik) • Batas waktumaksimal ADODB untukterhubungke Database. • CommandTimeout (satuan = detik) • Batas waktumaksimal ADODB untukmengeksekusisebuah query. • CursorLocation • Menetapkankoneksiuntukmembentuk cursor disisi Client. • Open • Perintahuntukmembukakoneksike database. • * ConnectionStringdapatdiambildari ADODC yang telahdisetting

  13. Setting ADODB • Untuk menutup koneksi ADODB : If Not Cn Is Nothing Then Cn.Close Set Cn = Nothing End If If Not Cn Is Nothing Then Untuk memeriksa apakah koneksi telah terbentuk atau belum. Cn.Close Untuk menutup koneksi ADODB ke database. Set Cn = Nothing Untuk menghilangkan setting database pada ADODB.

  14. Adodc Vs Adodb • Metode Insert / AddNew • Adodc Adodc1.Recordset.AddNew Adodc1.Recordset.Fields(“Field1”) = Text1.Text . Adodc1.Recordset.Update Adodc1.Refresh • Adodb Dim Rs As Adodb.Recordset Set Rs = New Adodb.Recordset Rs.Open “Query”,[Active Connection],adOpenDynamic,adLockOptimistic Rs.AddNew Rs(“Field1”) = Text1.Text . Rs.Update Rs.Close Set Rs = Nothing

  15. Adodc Vs Adodb • Metode Update • Adodc Adodc1.RecordSource = [Query] Adodc1.Refresh If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.Fields(“Field1”) = Text1.Text . Adodc1.Recordset.Update End If Adodc1.Refresh • Adodb Dim Rs As Adodb.Recordset Set Rs = New Adodb.Recordset Rs.Open [Query],[Active Connection],adOpenDynamic,adLockOptimistic If Not Rs.EOF Then Rs(“Field1”) = Text1.Text . Rs.Update End If Rs.Close Set Rs = Nothing

  16. Adodc Vs Adodb • Metode Delete • Adodc Adodc1.RecordSource = [Query] Adodc1.Refresh If Not Adodc1.Recordset.EOF Then Text1.Text = Adodc1.Recordset.Fields(“Field1”) . Data1.Recordset.Delete End If • Adodb Dim Rs As Adodb.Recordset Set Rs = New Adodb.Recordset Rs.Open [Query],[Active Connection],adOpenDynamic,adLockOptimistic If Not Rs.EOF then Text1.Text = Rs(“Field1”) . Rs.Delete End If Rs.Close Set Rs = Nothing

More Related