Problem with ComboBox - SystemDataRowView

0

I have a problem. My software has a order registration screen and there are some Combo Boxes that pull certain information according to what is selected in the Product field (Cake, Candy or Cupcake). They are 3 combobox: Cover, Type and Filling.

However, it is giving an error: when I select a particular product the Combo Box appears the information of the fields related to the selected product, but when I change the product all Combo Box no longer show the options (which comes directly of the Database, reminding again) and show the SystemDataRowView error. Could someone help me with what would be going wrong?

private void cmbProduto_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (cmbProduto.Text.Equals("Bolo"))
        {
            //Comando que se for selecionado Bolo no combox Produto dará um select nos combobox TIPO, COBERTURA E RECHEIO das tabelas relacionadas com bolo
            MySqlConnection coni = new MySqlConnection();
            coni.ConnectionString = ("server=localhost; user id=root; database=confeitaria; Password='';");
            coni.Open();
            MySqlCommand come = new MySqlCommand();
            come.Connection = coni;
            come.CommandText = "select nome_bolo_tipo from bolo_tipo";
            MySqlDataReader drt = come.ExecuteReader();
            DataTable dte = new DataTable();
            dte.Load(drt);
            cmbTipo.DisplayMember = "nome_bolo_tipo";
            cmbTipo.DataSource = dte;

            MySqlConnection cono = new MySqlConnection();
            cono.ConnectionString = ("server=localhost; user id=root; database=confeitaria; Password='';");
            cono.Open();
            MySqlCommand comi = new MySqlCommand();
            comi.Connection = cono;
            comi.CommandText = "select nome_bolo_recheio from bolo_recheio";
            MySqlDataReader drte = comi.ExecuteReader();
            DataTable dten = new DataTable();
            dten.Load(drte);
            cmbRecheio.DisplayMember = "nome_bolo_recheio";
            cmbRecheio.DataSource = dten;

            MySqlConnection oi = new MySqlConnection();
            oi.ConnectionString = ("server=localhost; user id=root; database=confeitaria; Password='';");
            oi.Open();
            MySqlCommand tchau = new MySqlCommand();
            tchau.Connection = oi;
            tchau.CommandText = "select nome_bolo_cobertura from bolo_cobertura";
            MySqlDataReader bb = tchau.ExecuteReader();
            DataTable cc = new DataTable();
            cc.Load(bb);
            cmbCobertura.DisplayMember = "nome_bolo_cobertura";
            cmbCobertura.DataSource = cc;
        }
        else if (cmbProduto.Text.Equals("Doce"))
        {
            //Comando que se for selecionado Doce no combox Produto dará um select nos combobox TIPO, COBERTURA E RECHEIO das tabelas relacionadas com doce
            MySqlConnection coniw = new MySqlConnection();
            coniw.ConnectionString = ("server=localhost; user id=root; database=confeitaria; Password='';");
            coniw.Open();
            MySqlCommand comeh = new MySqlCommand();
            comeh.Connection = coniw;
            comeh.CommandText = "select nome_doce_tipo from doce_tipo";
            MySqlDataReader drtv = comeh.ExecuteReader();
            DataTable dtep = new DataTable();
            dtep.Load(drtv);
            cmbTipo.DisplayMember = "nome_doce_tipo";
            cmbTipo.DataSource = dtep;

            MySqlConnection oit = new MySqlConnection();
            oit.ConnectionString = ("server=localhost; user id=root; database=confeitaria; Password='';");
            oit.Open();
            MySqlCommand tchauc = new MySqlCommand();
            tchauc.Connection = oit;
            tchauc.CommandText = "select nome_doce_cobertura from doce_cobertura";
            MySqlDataReader bbj = tchauc.ExecuteReader();
            DataTable ccl = new DataTable();
            ccl.Load(bbj);
            cmbCobertura.DisplayMember = "nome_doce_cobertura";
            cmbCobertura.DataSource = ccl;
        }
        else if (cmbProduto.Text.Equals("Cupcake"))
        {
            //Comando que se for selecionado Cupcake no combox Produto dará um select nos combobox TIPO, COBERTURA E RECHEIO das tabelas relacionadas com cupcake
            //Comando que se for selecionado Bolo no combox Produto dará um select nos combobox TIPO, COBERTURA E RECHEIO das tabelas relacionadas com bolo
            MySqlConnection coni = new MySqlConnection();
            coni.ConnectionString = ("server=localhost; user id=root; database=confeitaria; Password='';");
            coni.Open();
            MySqlCommand come = new MySqlCommand();
            come.Connection = coni;
            come.CommandText = "select nome_cup_tipo from cupcake_tipo";
            MySqlDataReader drto = come.ExecuteReader();
            DataTable dteo = new DataTable();
            dteo.Load(drto);
            cmbTipo.DisplayMember = "nome_cup_tipo";
            cmbTipo.DataSource = dteo;

            MySqlConnection cono = new MySqlConnection();
            cono.ConnectionString = ("server=localhost; user id=root; database=confeitaria; Password='';");
            cono.Open();
            MySqlCommand comi = new MySqlCommand();
            comi.Connection = cono;
            comi.CommandText = "select nome_cup_recheio from cupcake_recheio";
            MySqlDataReader drteu = comi.ExecuteReader();
            DataTable dtenu = new DataTable();
            dtenu.Load(drteu);
            cmbRecheio.DisplayMember = "nome_cup_recheio";
            cmbRecheio.DataSource = dtenu;

            MySqlConnection oi = new MySqlConnection();
            oi.ConnectionString = ("server=localhost; user id=root; database=confeitaria; Password='';");
            oi.Open();
            MySqlCommand tchau = new MySqlCommand();
            tchau.Connection = oi;
            tchau.CommandText = "select nome_cup_cobertura from cupcake_cobertura";
            MySqlDataReader bbz = tchau.ExecuteReader();
            DataTable ccz = new DataTable();
            ccz.Load(bbz);
            cmbCobertura.DisplayMember = "nome_cup_cobertura";
            cmbCobertura.DataSource = ccz;
        }

    
asked by anonymous 18.11.2016 / 12:07

1 answer

0

Guilherme,

Try to put the ValueMember too.

cmbTipo.ValueMember = "nome_bolo_tipo";
    
20.11.2016 / 02:10