Combobox não é preenchida
06/07/2012
0
Fiz esse código e não funciona. Dá esse erro:
Complex DataBinding accepts as a data source either an IList or an IListSource.
Esse é o método para preencher a combo:
private string preencheCombo(ComboBox cbo)
{
StringBuilder comandoSQL = new StringBuilder();
comandoSQL.AppendLine(SELECT );
comandoSQL.AppendLine( NOME );
comandoSQL.AppendLine( ,CODCLI );
comandoSQL.AppendLine(FROM );
comandoSQL.AppendLine(CLIENTES );
MySqlConnection m_conexao = new MySqlConnection();
m_conexao.ConnectionString = ConfigurationManager.ConnectionStrings[conexaoMysql].ConnectionString;
this.comando = new MySqlCommand(comandoSQL.ToString(), m_conexao);
try
{
DataTable dt = new DataTable();
m_conexao.Open();
comando.ExecuteNonQuery();
MySqlDataReader dr = comando.ExecuteReader();
cbo.DataSource = dr;
cbo.ValueMember = NOME;
}
catch (Exception excecao)
{
Erro = excecao.Message;
}
finally
{
m_conexao.Close();
}
Complex DataBinding accepts as a data source either an IList or an IListSource.
Esse é o método para preencher a combo:
private string preencheCombo(ComboBox cbo)
{
StringBuilder comandoSQL = new StringBuilder();
comandoSQL.AppendLine(SELECT );
comandoSQL.AppendLine( NOME );
comandoSQL.AppendLine( ,CODCLI );
comandoSQL.AppendLine(FROM );
comandoSQL.AppendLine(CLIENTES );
MySqlConnection m_conexao = new MySqlConnection();
m_conexao.ConnectionString = ConfigurationManager.ConnectionStrings[conexaoMysql].ConnectionString;
this.comando = new MySqlCommand(comandoSQL.ToString(), m_conexao);
try
{
DataTable dt = new DataTable();
m_conexao.Open();
comando.ExecuteNonQuery();
MySqlDataReader dr = comando.ExecuteReader();
cbo.DataSource = dr;
cbo.ValueMember = NOME;
}
catch (Exception excecao)
{
Erro = excecao.Message;
}
finally
{
m_conexao.Close();
}
Pjava
Curtir tópico
+ 0
Responder
Posts
06/07/2012
Pjava
Resolvi com esse código:
MySqlConnection m_conexao = new MySqlConnection();
m_conexao.ConnectionString = ConfigurationManager.ConnectionStrings[conexaoMysql].ConnectionString;
this.comando = new MySqlCommand(comandoSQL.ToString(), m_conexao);
try
{
m_conexao.Open();
comando.ExecuteNonQuery();
MySqlDataReader dr = comando.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
cbo.Items.Add(dr[CODCLI].ToString() + - + dr[NOME].ToString());
}
}
}
catch (Exception excecao)
{
Erro = excecao.Message;
}
finally
{
m_conexao.Close();
}
MySqlConnection m_conexao = new MySqlConnection();
m_conexao.ConnectionString = ConfigurationManager.ConnectionStrings[conexaoMysql].ConnectionString;
this.comando = new MySqlCommand(comandoSQL.ToString(), m_conexao);
try
{
m_conexao.Open();
comando.ExecuteNonQuery();
MySqlDataReader dr = comando.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
cbo.Items.Add(dr[CODCLI].ToString() + - + dr[NOME].ToString());
}
}
}
catch (Exception excecao)
{
Erro = excecao.Message;
}
finally
{
m_conexao.Close();
}
Responder
Clique aqui para fazer login e interagir na Comunidade :)