过滤comboBox(依赖于comboBox)的mysql

编程入门 行业动态 更新时间:2024-10-10 03:33:46
本文介绍了过滤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

本文发布于:2023-11-13 04:34:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583442.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:依赖于   comboBox   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!