Questions about loading combobox in C # with MySql database

1

Good afternoon, I'd like to know how I can populate a C # combo box with data from a table in MySQL. I am making an application for a jewelry store, and I would like to know how I can fill out the combo box of suppliers through your code (or id, as you wish) I need to register your code through your name, this is the method I did: p>

// part to load the vendor combobox

        MySqlConnection con = new MySqlConnection("server=localhost; port=3306; User Id=root; database=dbbijus;");
        con.Open();
        MySqlCommand com = new MySqlCommand();
        com.Connection = con;
        com.CommandText = "select * from fornecedor";
        MySqlDataReader dr = com.ExecuteReader();
        DataTable dt = new DataTable();
        dt.Load(dr);
        cbFornecedor.DisplayMember = "NomeFant";
        cbFornecedor.ValueMember = "CodFornecedor";
        cbFornecedor.SelectedItem = "";
        cbFornecedor.Refresh();
        cbFornecedor.DataSource = dt;

        //parte para carregar o combobox de categorias

        com.CommandText = "select codcategoria,nomecategoria from categoria ";
        MySqlDataReader dred = com.ExecuteReader();
        DataTable dta = new DataTable();
        dta.Load(dred);
        cbCategoria.DisplayMember = "NomeCategoria";
        cbCategoria.ValueMember = "CodCategoria";
        cbCategoria.SelectedValue = "";
        cbCategoria.DataSource = dta;

Using this method I even pull the vendor name, but only the name, what I need, as I said, and register the vendor name through the code

    
asked by anonymous 06.11.2017 / 16:41

0 answers