wxy新人小白 2019-07-17 11:33 采纳率: 31.3%
浏览 428
已采纳

二个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条回答 默认 最新

  • threenewbee 2019-07-17 13:02
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 gradle环境下javafx项目如何使用druid连接池
  • ¥15 服务器打印水晶报表问题
  • ¥15 初学者用plt报错,求解答
  • ¥18 深度学习tensorflow1,ssdv1,coco数据集训练一个模型
  • ¥100 关于注册表摄像头和麦克风的问题
  • ¥30 代码本地运行正常,但是TOMCAT部署时闪退
  • ¥15 关于#python#的问题
  • ¥15 主机可以ping通路由器但是连不上网怎么办
  • ¥15 数据库一张以时间排好序的表中,找出多次相邻的那些行
  • ¥50 关于DynamoRIO处理多线程程序时候的问题