weixin_44138934
wxy新人小白
2019-07-17 11:33
采纳率: 73.7%
浏览 385

二个combox 联动(combox都是连接数据库添加值的),逻辑问题,求各位大神帮帮忙

 private SQLiteConnection m;
        private SQLiteConnection m1;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string dbPath = @"D:\历年高考分数.db";
            string sq = @"Data Source=" + dbPath;
            m = new SQLiteConnection(sq);
            m.Open();
            SQLiteDataAdapter mAdapter = new SQLiteDataAdapter("select province from combox1值", m);
            DataSet ds = new DataSet();
            mAdapter.Fill(ds);
            DataTable dt = ds.Tables[0];
            comboBox1.DataSource = dt;
            comboBox1.ValueMember = "province";
            comboBox1.SelectedIndex = 0;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string dbPath1 = @"D:\历年高考分数.db";
            string sq1 = @"Data Source=" + dbPath1;
            m1 = new SQLiteConnection(sq1);
            m1.Open();
            SQLiteDataAdapter mAdapter1 = new SQLiteDataAdapter("select  from combox2值", m1);
            DataSet ds1 = new DataSet();
            mAdapter1.Fill(ds1);
            DataTable dt1 = ds1.Tables[0];
            comboBox2.DataSource = dt1;
            //comboBox2.ValueMember = "province";
            comboBox2.SelectedIndex = 0;
            //comboBox3.DisplayMember = "列标题";
           // m1.Close();
            if (comboBox1.SelectedIndex == 0)
            {
                comboBox2.Items.Clear();
                comboBox2.ValueMember = "四川";
            }
            else if (comboBox1.SelectedIndex == 1)
            {
                comboBox2.Items.Clear();
                comboBox2.ValueMember = "江苏";
            }
            else if (comboBox1.SelectedIndex == 2)
            {
                comboBox2.Items.Clear();
                comboBox2.ValueMember = "广州";
            }
            else if (comboBox1.SelectedIndex == 3)
            {
                comboBox2.Items.Clear();
                comboBox2.ValueMember = "直辖市";
            }
            m1.Close();
        }![图片说明](https://img-ask.csdn.net/upload/201907/17/1563334144_906636.png)![图片说明](https://img-ask.csdn.net/upload/201907/17/1563334358_948155.png)![图片说明](https://img-ask.csdn.net/upload/201907/17/1563334371_450607.png)




  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • caozhy
    已采纳

    SQLiteDataAdapter mAdapter1 = new SQLiteDataAdapter("select from combox2值", m1);
    ->
    SQLiteDataAdapter mAdapter1 = new SQLiteDataAdapter("select 这里写字段名 from combox2值", m1);

    点赞 评论

相关推荐