How to add items from database to Listbox control using C#
The following code binds the PlayerDetails table with the listbox
string sConString = GetConnectionString("TeamDBConnectionString");
SqlConnection Con = new SqlConnection(sConString);
Con.Open();
//Command Text
String sSQLCmdText = "Select * from PlayerDetails";
//Create a new SQL Data Adapter
SqlDataAdapter DA = new SqlDataAdapter(sSQLCmdText , Con);
DataSet DS = new DataSet("PlayerDS"); //DataSet
DS.Clear();
DA.Fill(DS, "Player");
listBox1.DisplayMember = "PlayerName";
listBox1.ValueMember = "PlayerID";
listBox1.DataSource = DS.Tables["Player"];
Con.Close();