过滤comboBox(依赖于comboBox)的mysql [英] Filter comboBox (dependent to comboBox) mysql

查看:134
本文介绍了过滤comboBox(依赖于comboBox)的mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图根据另一个组合框制作一个组合框过滤器。它来自同一数据库中的两个不同的表。 comboBox2已从类型表中填充。下一个应显示另一个值,取决于您在第一个组合框中选择的内容



这是组合框的代码





 MySqlConnection con = new MySqlConnection(datasource = localhost; port = 3306; username = root; password = Deprisa!79849;); 
private void comboBox2_SelectedIndexChanged(object sender,EventArgs e)
{
// comboBox2,3和9
comboBox3.SelectedIndex = -1;
comboBox3.Items.Clear();
if(con.State == ConnectionState.Closed)
{
con.Open();
}

MySqlCommand cmd = new MySqlCommand(select of Distinct(idbrand)from machine where idtype ='+ comboBox2.SelectedItem +',con);

MySqlDataReader rd = cmd.ExecuteReader();
while(rd.Read())
{
comboBox3.Items.Add(rd [0]);
}

rd.Close();
cmd.Dispose();



}

private void comboBox3_SelectedIndexChanged(object sender,EventArgs e)
{
comboBox9.SelectedIndex = -1 ;
comboBox9.Items.Clear();

if(con.State == ConnectionState.Closed)
{
con.Open();
}

MySqlCommand cmd = new MySqlCommand(select idmodel from machine where idtype ='+ comboBox2.SelectedItem +'and idmodel ='+ comboBox3.SelectedItem +', CON);

MySqlDataReader rd = cmd.ExecuteReader();

while(rd.Read())
{
comboBox9.Items.Add(rd [0]);
}
rd.Close();
cmd.Dispose();
}

解决方案

那你的问题是什么?你得到的错误是什么?


im trying to make a combobox filter depending from another combobox. its from two different tables in the same database. comboBox2 is already filled from type table. the next should display another value dpending on what you selected in the first combobox

this is the code for the combobox


MySqlConnection con = new MySqlConnection("datasource=localhost;port=3306;username=root;password=Deprisa!79849;");
       private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
       {
           //comboBox2,3,and 9
           comboBox3.SelectedIndex = -1;
           comboBox3.Items.Clear();
           if (con.State == ConnectionState.Closed)
           {
               con.Open();
           }

           MySqlCommand cmd = new MySqlCommand("Select Distinct(idbrand) from machine where idtype='" + comboBox2.SelectedItem + "'", con);

           MySqlDataReader rd = cmd.ExecuteReader();
           while (rd.Read())
           {
               comboBox3.Items.Add(rd[0]);
           }

           rd.Close();
           cmd.Dispose();



       }

       private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
       {
           comboBox9.SelectedIndex = -1;
           comboBox9.Items.Clear();

           if (con.State == ConnectionState.Closed)
           {
               con.Open();
           }

           MySqlCommand cmd = new MySqlCommand("select idmodel from machine where idtype='" + comboBox2.SelectedItem + "' and idmodel = '" + comboBox3.SelectedItem + "'", con);

           MySqlDataReader rd = cmd.ExecuteReader();

           while (rd.Read())
           {
               comboBox9.Items.Add(rd[0]);
           }
           rd.Close();
           cmd.Dispose();
       }

解决方案

So what is your question ? and what is the error you are getting ?


这篇关于过滤comboBox(依赖于comboBox)的mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆