二个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个回答

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问