combox1有值时combox2显示与combox1有关的值
2016-06-03 10:14
176 查看
private void comboBox2_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedItem == null || comboBox1.Text == "-请选择-")
{
SqlDataAdapter da1 = new SqlDataAdapter("select distinct Buys.GId,GName from Buys,Goods where Buys.GId = Goods.GId", cn);
DataSet ds1 = new DataSet();
//comboBox2.Items.Clear();
da1.Fill(ds1, "Good");
DataRow dr1 = ds1.Tables["Good"].NewRow();
dr1["GId"] = "0";
dr1["GName"] = "-请选择-";
ds1.Tables["Good"].Rows.InsertAt(dr1, 0);
comboBox2.DataSource = ds1.Tables["Good"];
comboBox2.DisplayMember = "GName";
comboBox2.ValueMember = "GId";
cn.Close();
}
else
{
SqlDataAdapter da2 = new SqlDataAdapter("select distinct Buys.GId,GName from Buys,Goods where Buys.GId = Goods.GId and Buys.WorId = " + comboBox1.SelectedValue.ToString() + "", cn);
DataSet ds2 = new DataSet();
//comboBox2.Items.Clear();
da2.Fill(ds2, "Good");
DataRow dr2 = ds2.Tables["Good"].NewRow();
dr2["GId"] = "0";
dr2["GName"] = "-请选择-";
ds2.Tables["Good"].Rows.InsertAt(dr2, 0);
comboBox2.DataSource = ds2.Tables["Good"];
comboBox2.DisplayMember = "GName";
comboBox2.ValueMember = "GId";
cn.Close();
}
}
{
if (comboBox1.SelectedItem == null || comboBox1.Text == "-请选择-")
{
SqlDataAdapter da1 = new SqlDataAdapter("select distinct Buys.GId,GName from Buys,Goods where Buys.GId = Goods.GId", cn);
DataSet ds1 = new DataSet();
//comboBox2.Items.Clear();
da1.Fill(ds1, "Good");
DataRow dr1 = ds1.Tables["Good"].NewRow();
dr1["GId"] = "0";
dr1["GName"] = "-请选择-";
ds1.Tables["Good"].Rows.InsertAt(dr1, 0);
comboBox2.DataSource = ds1.Tables["Good"];
comboBox2.DisplayMember = "GName";
comboBox2.ValueMember = "GId";
cn.Close();
}
else
{
SqlDataAdapter da2 = new SqlDataAdapter("select distinct Buys.GId,GName from Buys,Goods where Buys.GId = Goods.GId and Buys.WorId = " + comboBox1.SelectedValue.ToString() + "", cn);
DataSet ds2 = new DataSet();
//comboBox2.Items.Clear();
da2.Fill(ds2, "Good");
DataRow dr2 = ds2.Tables["Good"].NewRow();
dr2["GId"] = "0";
dr2["GName"] = "-请选择-";
ds2.Tables["Good"].Rows.InsertAt(dr2, 0);
comboBox2.DataSource = ds2.Tables["Good"];
comboBox2.DisplayMember = "GName";
comboBox2.ValueMember = "GId";
cn.Close();
}
}
相关文章推荐
- Unity5.x依赖打包
- Bootstrap- Modal对话框如何在关闭时触发事件
- 在需要HTML代码的PHP脚本中,多用这么几种方法
- android混淆打包报错的一种可能java.io.IOException: Can't read [D:\workspace\android0428\libs\pwd_sdk_proguard.ja
- Android实现js及webview交互之在html页面中调用系统摄像头
- js判断某个字符出现的次数的简单实例
- 图片不能包含alpha通道或透明度问题解决方法
- jquery锚点跳转+自动显示隐藏回到顶端代码
- TCP三次握手,4次挥手
- Draw nicer Classification and Regression Trees with the rpart.plot package
- 数据结构上机测试2-2:单链表操作B
- 盐值加密介绍
- 软件就是未来:工业4.0时代下的工业软件
- Android day6:JAVA运算符、流程(循环)、数组
- git常用命令的使用(2)
- 关系型数据库之Mysql引擎-日志-用户管理(三)
- AndroidStudio中ADB Wifi插件
- 硬盘发生故障数据还能恢复吗
- Vim常用指令笔记
- Android框架进阶--ThinkAndroid注解机制(2)