Click here to Skip to main content
15,797,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone!,

In C# winform application I want to display all the names of the tables which exists in my StoreDatabase. into a combobox (Dropdown).

In my Store database there are some tables which I want to show inside the dropdown. As the end-user clicks the dropdown, It will show all the lists of tables.

Here is the code Which I m trying 

What I have tried:

// C# Source Code :

DataTable dt = new DataTable();
MySqlConnection conn = new MySqlConnection(@"Server=localhost;Database=Generalstore;Username=my********;Password:********;");
MySqlDataAdapter da = new MySqlDataAdapter(@"show tables", conn);


            if (dt.Rows.Count > 0)
comboBox1.DisplayMember = "alloyName";
comboBox1.ValueMember = "alloyName";
comboBox1.DataSource = dt;
Updated 13-Nov-22 17:05pm
Gerry Schmitz 13-Nov-22 16:06pm
M Imran Ansari 13-Nov-22 16:15pm    
Your code is looking good. What error you are getting?
adriancs 13-Nov-22 22:03pm    
@M Imran Ansari, he is typing the wrong column name. "alloyName" is not existed in "show tables"

1 solution

You are doing this:
comboBox1.DisplayMember = "alloyName";
comboBox1.ValueMember = "alloyName";
comboBox1.DataSource = dt;
which "alloyName" is not existed.

You can type this in stead:
foreach (DataRow dr in dt.Rows)
    comboBox1.Items.Add(dr[0] + "");
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900