1 / 12

Connection & Datareader

Connection & Datareader. Write Code. Pengenalan singkat. Proses Standar Penggunaan Koneksi Query DataReader Control. Create Interface. Debug and Deploy. Use Visual Studio .NET. Access Data. Debug and Deploy. Proses Standar. Koneksi. Query. Data Reader. Control.

duy
Download Presentation

Connection & Datareader

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. Connection & Datareader

  2. Write Code Pengenalan singkat • ProsesStandar • PenggunaanKoneksi • Query • DataReader • Control Create Interface Debug and Deploy Use Visual Studio .NET Access Data Debug and Deploy

  3. Proses Standar • Koneksi • Query • Data • Reader • Control

  4. Penggunaan Koneksi Setting Koneksinya • SqlConnection • Pasang ConnectionString • * Data Source / Server • * Initial Catalog / Database • * Integrated Security • * User ID • * Password • Contoh : • Dim xkoneksi as new sqlconnection • Xkoneksi.connectionString=“Data Source=localhost;Initial Catalog=Master;Integrated Security=true“ SqlConnection Database

  5. Query Ambil Data • SqlCommand • Parameter • * Query • * SqlConnection • Contoh : • Dim query as string • Dim xcom as new sqlcommand • Query = “select nim, nama from mhs“ • Xcom.commandtext(query,xkoneksi) SqlCommand SqlConnection Database

  6. Data Reader Penggunaan DataReader • Tidak perlu di instance-kan • dim xread as sqldatareader • 2. SqlCommand.ExecuteReader • 3. Forward Only Use SqlDataReader SqlCommand SqlConnection Database

  7. Control • Command • DataReader (Forward Only Use Looping • Pembacaan data : • * xread([posisi_kolom]) atau xread([nama_kolom]) • * xread.item([posisi_kolom]) atau • xread.item([nama_kolom]) • * xread.Get([tipe_data]) atau xread([posisi_kolom])

  8. Test Case – Design UI

  9. Langkah pertama • Deklarasikan variable yang dibutuhkanyaitu: • SQLConnection • SQLCommand • SQLDataReader Dim xkoneksiAs New SqlClient.SqlConnection Dim xcomAs New SqlClient.SqlCommand Dim xreadAs SqlClient.SqlDataReader

  10. Langkah kedua • Buat variable untuk menyimpan query Dim strSQL as new String(“”) • Pada event Command1 click: • Isikan connectionString pada object koneksi. • Isikan query pada variable sqlStr • Isikan sqlStr pada property cmd.commandText • Isikan property cmd.connection • Buka connecntion • Isikan xReader dengan cmd.executeReader

  11. xcom.CommandText = “select * from Tugas where NamaMhs like & ‘” Textbox1.Text & “%’” xkoneksi.ConnectionString = “Data Source=localhost;Initial Catalog=PV;Integrated Security=true“ xcom.Connection = xkoneksi xkoneksi.Open() xread = xcom.ExecuteReader

  12. Langkah ketiga – Isi Listbox Ifxread.HasRows Then Do While xread.Read Listbox1.Items.Add(xread.item(0)) loop End if Xread.close() Xkoneksi.close()

More Related