Load Data into Combox in Vb.net at Runtime

October 10, 2009

First you want to place combo box on form then rename it as “combo1″ & Access database with table and have 2 or 3 fileds.

<strong><span style="color: #339966;">Declare data & OleDB in general area</span></strong>


Public Class form1

<!-- Easy AdSense V2.75 --> <!-- Post[count: 2] --><strong><span style="color: #339966;">Declare data adapter, data set, command string, record reader</span></strong>

Dim da As OleDbDataAdapter
 Dim ds As DataSet
 Dim cmd As OleDbCommand
 Dim redred As OleDbDataReader

<strong><span style="color: #339966;">after this write following code lines in your Form Load Event</span></strong>

Dim con As New OleDb.OleDbConnection
 con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = D:\project\login.mdb"
 cmd = New OleDb.OleDbCommand("select u_n from Table1", con)
 redred = cmd.ExecuteReader
 While redred.Read()

End While
 End Try
 End Sub
 End Class

now you can play your project and extend your combo box you will see all data in your combo box that is from your database’s table.