' Database connection object
Dim oConn as new oledb.oledbconnection("Connectionstring")
oConn.open
' DataAdapter to get the information out of the database
Dim oDA as new DataAdapter("SELECT UserName, UserID FROM Users",oConn)
' Dataset used to store the data retrieved from the database
Dim oDS as new DataSet
' Fill the dataset with info from the database
oDA.Fill(oDS)
' Set your listbox datasource to the dataset
MyListBox1.DataSource = oDS
' Set the text values (The values that the will appear in the listbox)
MyListBox1.DataTextMember = "UserName"
' Set the vallue values (The values that are associated with the text items that appear in the listbox)
MyListBox1.DataValueMember = "UserID"
' Bind the listbox to the datasource
MyListBox1.DataBind()