How to Get Data from Database into ComboBox Control Using VB.net

 Video Instruction

Source Code:
Public Sub DataToComboBox(ByVal cbo As ComboBox, ByVal SQLSTRING As String, ByVal FieldName As String) Dim cmd As OleDb.OleDbCommand Dim dr As OleDb.OleDbDataReader CheckConectionState() cmd = New OleDb.OleDbCommand(SQLSTRING, CNN) ' CNN is connection string i already use in Module1 dr = cmd.ExecuteReader cbo.Items.Clear() While dr.Read() If Not cbo.Items.Contains(dr(FieldName)) Then cbo.Items.Add(dr(FieldName)) End If End While dr.Close() End Sub 2.Form1 Coding: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click CheckConectionState() DataToComboBox(ComboBox1, "SELECT * FROM tbl_Products", "Items") DataToComboBox(ComboBox2, "SELECT * FROM tbl_Products", "Made_In") MsgBox("Load data completed", , "Arsarin Kh, Please help to subscribe, Thanks!") CNN.Close() End Sub

Post a Comment

0 Comments