Upload presentasi
Presentasi sedang didownload. Silahkan tunggu
Diterbitkan olehAna Jantur Telah diubah "9 tahun yang lalu
1
Matakuliah: T0063/Pemrograman Visual Tahun: 2005 Versi: 1/0 1
2
Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : Mendemonstrasikan penggunaan database yang ditunjang oleh pemrograman visual (C3) 2
3
Pemrograman Database Database ADO Connection Connection String Argument State Command RecordSet Cursor Type Fields Connection in Action Command in Action RecordSet in Action Processing Data Query Data Modifying Data 3
4
Akses database ◦ ODBC ◦ DAO ◦ RDO ◦ ADO 4
5
ActiveX Data Object (ADO) ◦ Generasi paling baru untuk mengakses data ◦ Terdiri : Consumer Service Data provider 5
6
ADO Object Model Connection ◦ Error ◦ Property Command ◦ Parameter ◦ Property Recordset ◦ Fields ◦ Property 6
7
Connection Characteristics ◦ Mewakili satu session dengan data source Properties ◦ ConnectionString ◦ Provider ◦ ConnectionTimeOut (default 30 detik) ◦ CommandTimeOut (default 30 detik) ◦ CursorLocation (adUseClient atau adUseServer) ◦ State ◦ Errors Events ◦ WillConnect, ConnectComplete, Disconnect ◦ WillExecute, ExecuteComplete, Methods ◦ Open ◦ Execute 7
8
ArgumentDescription Data SourceThe name of the SQL Server or the name of the MDB database to which you want to connect. When connecting to an ODBC source, this argument can also be the name of a Data Source Name (DSN). DSNAn ODBC source name registered on the current machine; this argument can replace the Data Source argument. FilenameA file that contains information about the connection; this argument can be an ODBC DSN file or a Microsoft Data Link (UDL) file. Initial CatalogThe name of the default database. When connecting to an ODBC source, you can also use the Database argument. PasswordThe user's password. When connecting to an ODBC source, you can use the PWD argument. You don't need to pass your user ID and password if you're connecting to SQL Server and you use integrated security. Persist Security Info True if ADO stores the user ID and the password in the data link. ProviderThe name of the OLE DB provider; the default value is MSDASQL, the provider for ODBC sources. User IDThe user's name. When connecting to an ODBC source, you can use the UID argument instead. 8
9
ValueDescription 0-adStateClosedThe connection is closed. 1-adStateOpenThe connection is open. 2-adStateConnectingThe connection is being opened. 4-adStateExecutingThe connection is executing a command. 8-adStateFetchingA Recordset is being retrieved. 9
10
Command Characteristics ◦ Berisi sintak SQL dan parameter untuk dieksekusi Properties ◦ CommandText ◦ ActiveConnection ◦ Parameters Events ◦ Tidak ada Methods ◦ Execute ◦ Cancel 10
11
RecordSet Characteristics ◦ Interface data Properties ◦ Source ◦ ActiveConnection ◦ DataSource ◦ Filter ◦ CursorLocation (2-adUseServer atau 3-adUseClient ) ◦ CursorType Events ◦ FetchProgress, FetchComplete ◦ WillMove, MoveComplete ◦ EndOfRecordset ◦ WillChangeField, FieldChangeComplete ◦ WillChangeRecord, RecordChangeComplete Methods ◦ Open 11
12
ValueDescription 0-adOpenForwardOnlyServer side cursor, you can navigate a forward- only Recordset only by using the MoveNext method 1-adOpenKeysetKeyset cursors are similar to dynamic cursors, but they don't include records added by other users 2-adOpenDynamicDynamic cursors consist of a set of bookmarks to the actual data in the data source, automatically updated when other users add or delete a record or change any record already in the Recordset 3-adOpenStaticActually a copy of the data coming from the database. Static cursors create a fully scrollable snapshot of all the records 12
13
Fields Cara mengakses field : ◦ rs.Fields(Index).Value ◦ rs.Fields(“FieldName”).Value ◦ rs.!FieldName 13
14
Persiapan ◦ Database ◦ Reference 14
15
Connection ◦ Deklarasi object Connection ◦ Tentukan Data Provider ◦ Tentukan spesifikasi sumber data ◦ Open Connection 15
16
16 Koneksi ke Access Koneksi ke SQLServer
17
Command ◦ Deklarasi object Command ◦ Hubungkan command dengan koneksi aktif ◦ Tentukan spesifikasi query data ◦ Jalankan command 17
18
18
19
RecordSet ◦ Deklarasi object recordset ◦ Jalankan command dan tampung ke dalam recordset 19
20
Cara Lain Akses Data * Untuk mempersingkat perintah, biasanya Command jarang dipakai Execute dilakukan langsung oleh connection, tanpa melalui command, dan ditampung oleh recordset 20 *Masih banyak cara lainnya, coba eksplor cara akses data cukup menggunakan recordset saja
21
Bandingkan hasilnya dengan program sebelumnya 21
22
Struktur Navigasi Recordset ◦ BOF, penanda awal record ◦ EOF, penanda akhir record ◦ MoveFirst, kembali ke posisi awal ◦ MoveLast, maju ke posisi akhir ◦ MovePrevious, kembali ke posisi sebelumnya ◦ MoveNext, maju ke posisi sesudahnya ◦ RecordCount, mengetahui jumlah record 22
23
Loop ◦ Recordset berisi collection data, sehingga untuk mengaksesnya diperlukan loop ◦ atau 23 Do List1.AddItem rs.Fields(0).Value rs.MoveNext Loop Until rs.EOF If rs.RecordCount <> 0 Then rs.MoveFirst Do List1.AddItem rs.Fields(0).Value rs.MoveNext Loop Until rs.EOF End If
24
Modifying Record ◦ Banyak record, menggunakan sintaks SQL ◦ Satu record, menggunakan recordset Sintaks SQL ◦ Select ◦ Insert ◦ Update ◦ Delete 24 SELECT * FROM table1 WHERE field=? INSERT INTO table1 (field1, field2) VALUES (newValue1, newValue2) UPDATE table1 SET field=newValue DELETE FROM table WHERE field1=?
25
25
26
Memodifikasi record tunggal AddNew ◦ Menambah record baru Delete ◦ Menghapus record aktif Modify ◦ Memodifikasi record aktif 26 rs.AddNew rs!fname = "Nana" rs!lname = “Sylva" rs.Update rsAuthors.Delete rs!fname = “Nana" rs!lname = “Sylva" rs.Update
27
Contoh : 27
Presentasi serupa
© 2024 SlidePlayer.info Inc.
All rights reserved.