private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = DB.getconn();
SqlCommand mycmm = new SqlCommand("Select 省 from 地级", conn);
SqlDataReader dr = mycmm.ExecuteReader();
ArrayList ary = new ArrayList();
while (dr.Read())
{
string sdr = dr[0].ToString().Trim();
if (!ary.Contains(sdr[0].ToString().Trim()))
{
ary.Add(sdr);
}
}
for (int i = 0; i < ary.Count; i++)
{
comboBox2.Items.Add(ary[i]);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Items.Clear();
SqlConnection conn = DB.getconn();
SqlCommand mycmm = new SqlCommand("Select 市 from 地级 where 省='" + comboBox1.SelectedItem.ToString() + "'", conn);
SqlDataReader dr = mycmm.ExecuteReader();
ArrayList ary = new ArrayList();
while (dr.Read())
{
string str = dr[0].ToString().Trim();
if (!ary.Contains(dr[0].ToString().Trim()))
{
ary.Add(str);
}
}
for (int i = 0; i < ary.Count; i++)
{
comboBox1.Items.Add(ary[i]);
}
}
为什么打开下拉列表时什么都没有是空白的
{
SqlConnection conn = DB.getconn();
SqlCommand mycmm = new SqlCommand("Select 省 from 地级", conn);
SqlDataReader dr = mycmm.ExecuteReader();
ArrayList ary = new ArrayList();
while (dr.Read())
{
string sdr = dr[0].ToString().Trim();
if (!ary.Contains(sdr[0].ToString().Trim()))
{
ary.Add(sdr);
}
}
for (int i = 0; i < ary.Count; i++)
{
comboBox2.Items.Add(ary[i]);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Items.Clear();
SqlConnection conn = DB.getconn();
SqlCommand mycmm = new SqlCommand("Select 市 from 地级 where 省='" + comboBox1.SelectedItem.ToString() + "'", conn);
SqlDataReader dr = mycmm.ExecuteReader();
ArrayList ary = new ArrayList();
while (dr.Read())
{
string str = dr[0].ToString().Trim();
if (!ary.Contains(dr[0].ToString().Trim()))
{
ary.Add(str);
}
}
for (int i = 0; i < ary.Count; i++)
{
comboBox1.Items.Add(ary[i]);
}
}
为什么打开下拉列表时什么都没有是空白的