120 likes | 231 Views
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.
E N D
Write Code Pengenalan singkat • ProsesStandar • PenggunaanKoneksi • Query • DataReader • Control Create Interface Debug and Deploy Use Visual Studio .NET Access Data Debug and Deploy
Proses Standar • Koneksi • Query • Data • Reader • Control
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
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
Data Reader Penggunaan DataReader • Tidak perlu di instance-kan • dim xread as sqldatareader • 2. SqlCommand.ExecuteReader • 3. Forward Only Use SqlDataReader SqlCommand SqlConnection Database
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])
Langkah pertama • Deklarasikan variable yang dibutuhkanyaitu: • SQLConnection • SQLCommand • SQLDataReader Dim xkoneksiAs New SqlClient.SqlConnection Dim xcomAs New SqlClient.SqlCommand Dim xreadAs SqlClient.SqlDataReader
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
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
Langkah ketiga – Isi Listbox Ifxread.HasRows Then Do While xread.Read Listbox1.Items.Add(xread.item(0)) loop End if Xread.close() Xkoneksi.close()