I am trying to populate a combo box with data but I cant get it work
public void fillZone()
{
string sql = "select location from zone";
MySqlDataAdapter zonedapter = new MySqlDataAdapter(sql,conn);
DataTable dt = new DataTable("zone");
zonedapter.Fill(dt);
}
I use fillZone() to get data from mysql and have it stored in a dataTable.I want to populate a combobox named zonecb with data from returned result above, as shown below
this.zonecb.ItemsSource = "Location";
this.zonecb.DisplayMemberPath = "Location";
my xml is as shown:
<ComboBox Canvas.Left="91" Canvas.Top="57" Height="23" Name="zonecb" Width="200" ItemsSource="{Binding}" />
Any ideas?
you will need to acces dt, i dont know if you call your fillzone only for filling combobox but i would suggest:
EDIT:
im using a same kind of method, but ith a postgreSql Database, by changing PgsqlDataAdapter to MySqlDataAdapter this might/should work
String str is your Query.
now you got a table wih all the data you need/wanted.
now you populated your combobox