cara menampilkan data ke dalam listbox - combobox

 

 


Imports System.Data.SqlClient

 

Public Class Latihan

Dim conn As SqlConnection
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim cmd As SqlCommand
Dim dr As SqlDataReader

 

Sub Koneksi()
conn = New SqlConnection("data source=user-pc\sqlexpress;initial catalog=dbnashir;integrated security=true")
conn.Open()
End Sub

 

Private Sub Latihan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call Koneksi()
cmd = New SqlCommand("select * from tblbarang", conn)
dr = cmd.ExecuteReader
Do While dr.Read
ListBox1.Items.Add(dr.Item("kode_barang"))
ComboBox1.Items.Add(dr.Item(1))
Loop
End Sub

End Class