Problem with Combobox - Systemdatarowview

Asked

Viewed 84 times

0

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

However, it is giving an error: when I select a particular product the Combo Box appear the information of the fields related to the selected product, but when I change product all the Combo Box no longer show the options (which comes directly from the database, recalling again) and shows the Systemdatarowview error. Someone could 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;
        }

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

1 answer

0

William,

Also try to put Valuemember.

cmbTipo.ValueMember = "nome_bolo_tipo";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.