Hi I'm trying to populate a dynamic created comboBox using data from a database, but it shows an exception (Object reference not set to an instance of an object). And I'm tired of looking. What is missing here? Thanks For all the help! (newbie here)
private void SetComboBoxItems()
{
foreach (Control control in panelMain.Controls)
{
ComboBox comboBox = control as ComboBox;
try
{
using (MySqlConnection connection = new MySqlConnection(Properties.Settings.Default.connectionString))
{
connection.Open();
MySqlCommand command = new MySqlCommand("SELECT * FROM home.data", connection);
MySqlDataReader dataReader = command.ExecuteReader();
while (dataReader.Read())
{
comboBox.Items.Add((string)dataReader["temp"]);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}