Hola, estoy generando un Databinding a un combobox, con el siguiente
codigo, pero me regresa un mensaje de error, La conexión no se cerró,
el estado actual de la conexión es abierto, cuando cambio las
propiedades del combobox y se las asigno al array.
private void button1_Click(object sender, EventArgs e)
{
// Trae las zonas al primer ComboBox
//Esto estaba antes de conectar el ComboBox con un
DataSource
//comboBox1.Items.Clear();
SqlDataReader myReader = null;
SqlCommand mySqlCommand = new SqlCommand("select zon_cve,
zon_Nombre from Zona", mySqlConnection);
try
{
mySqlConnection.Open();
myReader mySqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
ArrayList ListaCombo = new ArrayList();
while (myReader.Read())
{
//comboBox1.Items.Add(new
MyListItem(myReader["zon_cve"].ToString(),
myReader["zon_Nombre"].ToString()));
ListaCombo.Add(new
MyListItem(myReader["zon_cve"].ToString(),
myReader["zon_Nombre"].ToString()));
}
MessageBox.Show("All names loaded successfully!");
comboBox1.DataSource = ListaCombo;
comboBox1.DisplayMember = "Display";
comboBox1.ValueMember = "Value";
}
catch(Exception ex)
{
MessageBox.Show("Error occurred: " + ex.Message);
}
finally
{
if (myReader != null)
myReader.Close();
}
}
Leer las respuestas