Jump to content
RLamana

Pesquisa com combobox

Recommended Posts

RLamana

Boa Noite!

Eu estou buscando em vários sites uma pesquisa utilizando combobox(select) com banco de dados, mas tudo o que encontro são caixas de texto para o usurário escrever, mas não quero assim. Alguém pode me ajudar?

Share this post


Link to post
Share on other sites
N3lson

Boas, aqui tens uma forma (que costumo usar) 
 

string query = "SELECT ......";

DataTable dt = new DataTable("Pesquisa");

MySqlDataReader reader;

using(MySqlConnection con = new MySqlConnection(Controle.ConSql))
{
	using(MySqlCommand cmd = new MySqlCommand(query, con))
	{
    	con.Open();
   	    reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
        dt.Columns.Add("maquina");
        dt.Load(reader);
        comboBox1.ValueMember = "campoBasedados";
        comboBox1.DisplayMember = "campoBasedados";
        comboBox1.DataSource = dt;
       reader.Close();
  }
   con.Close();
}

 


You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.