Reputation: 159
I have a combo box in my windows application form. I have a table called menu-list in a MySQL database. When i click on the combo box i want the options to be the value of a particular row of the database table for example a row called wine has 2 values, for example red wine and white wine, so when i click on the combo box i want the options to be red wine and white wine
private void menustart_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'cmsDataSet.menulist' table. You can move, or remove it, as needed.
this.menulistTableAdapter.Fill(this.cmsDataSet.menulist);
}
I used the above code but it didnt work
Upvotes: 0
Views: 3533
Reputation: 217
Maybe some of these posts might help you to get a solution :
Solution 1
Solution 2
Solution 3
Try these and let me know if you could find a solution.
EDIT : Try this code.
string MyConString = "SERVER=localhost;" +
"DATABASE=yourDB;" +
"UID=root;" +
"PASSWORD=yourPassword;";
MySqlConnection connection = new MySqlConnection(MyConString);
string command = "select wine from menu-list";
MySqlDataAdapter da = new MySqlDataAdapter(command,connection);
DataTable dt = new DataTable();
da.Fill(dt);
foreach (DataRow row in dt.Rows)
{
string wine = string.Format("{0}", row.Item[0]);
yourCombobox.Items.Add(wine);
}
connection.Close();
Upvotes: 1