J
jmrsuarez
Hi, i am using a list named ListaCombo to populate a combo box with a
query, but when i execute the code,
comboBox1.DisplayMember = "Display"; it thows a "The
connection is already Open (state=Open)" error messages.
anyone can give me idea?
thanks
//TextDate.Text = "Hoy";
mySqlConnection =
new
SqlConnection(System.Configuration.ConfigurationManager.AppSettings.Get("ConnectionString"));
DateTime Date1 = System.DateTime.Now.AddDays(0);
string Day = System.Convert.ToString(Date1.Month);
string Month = System.Convert.ToString(Date1.Day);
string Year = System.Convert.ToString(Date1.Year);
string cadDate = Day +"/"+ Month +"/"+ Year;
TextDate.Text = cadDate;
// Cargando ComboBox
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!");
// Here, the code generate a error, already
open! ***
comboBox1.DataSource = ListaCombo;
comboBox1.DisplayMember = "Display";
comboBox1.ValueMember = "Value";
}
catch (Exception ex)
{
MessageBox.Show("Error occurred: " + ex.Message);
}
finally
{
if (myReader != null)
myReader.Close();
}
myReader.Close();
query, but when i execute the code,
comboBox1.DisplayMember = "Display"; it thows a "The
connection is already Open (state=Open)" error messages.
anyone can give me idea?
thanks
//TextDate.Text = "Hoy";
mySqlConnection =
new
SqlConnection(System.Configuration.ConfigurationManager.AppSettings.Get("ConnectionString"));
DateTime Date1 = System.DateTime.Now.AddDays(0);
string Day = System.Convert.ToString(Date1.Month);
string Month = System.Convert.ToString(Date1.Day);
string Year = System.Convert.ToString(Date1.Year);
string cadDate = Day +"/"+ Month +"/"+ Year;
TextDate.Text = cadDate;
// Cargando ComboBox
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!");
// Here, the code generate a error, already
open! ***
comboBox1.DataSource = ListaCombo;
comboBox1.DisplayMember = "Display";
comboBox1.ValueMember = "Value";
}
catch (Exception ex)
{
MessageBox.Show("Error occurred: " + ex.Message);
}
finally
{
if (myReader != null)
myReader.Close();
}
myReader.Close();