Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I select data from a table on mysql 5.1 and add these data in a combobox in c#?
Posted
Updated 31-Aug-10 3:17am
v2
Comments
Dalek Dave 31-Aug-10 9:17am    
Minor Edit for Grammar.

Try:
MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM myTable", connection);
DataTable dt = new DataTable();
da.Fill(dt);
cb.DataSource = dt;
 
Share this answer
 
Comments
Lantei 30-Aug-10 6:07am    
The 'cb' he mentioned was the instance of the combobox..and doing the above as he says will solve your problems..
Dalek Dave 31-Aug-10 9:18am    
Good Call
Use ADO.NET to interact with database.

1. Get data from database in a datatable or a dataset
2. use that datatable/database as a datasource of Combobox
3. define the datatext/datavalue field of combobox.
 
Share this answer
 
you should(can) select a field to display and a field to return value;
for example:
MIDL
cb.DisplayMember="Name";
cb.ValueMember="ID";
 
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