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();
}
}