1
good afternoon, I would like to know how I can fill a combo box C# 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 the suppliers combo box through your code (or id, as you wish) I need to register your code through your name, this is the method I made:
//part to load the combobox from suppliers
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 can even pull the name of the supplier, but only the name, what I need, as I said, and register the name of the supplier through the code
Managed to solve?
– LP. Gonçalves
No, I still have that problem
– Victor Berzotti