comboBox绑定数据库后SelectedIndexChanged事件出错

        comBox控件绑定数据库字段后,在窗体的Load事件之前就已经触发SelectedIndexChanged了,这时可以加一个标识,让其在Load事件之后激发。

bool flag;
        private void Education_Training_Load(object sender, EventArgs e)
        { 
            MyDBase DB = new MyDBase(DBUser.sserver, DBUser.DBName, DBUser.suser, DBUser.spasswd);         
            DataSet  DS = DB.GetRecordset("select distinct (year(date)) as date from education_train where PID=1");
            comboBox_Year.DataSource = DS.Tables[0];
            comboBox_Year.DisplayMember = "date";
            comboBox_Year.ValueMember = "date";
            flag = true;
            DB.DBClose();
        }
        private void comboBox_Year_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!flag) return;
            MyDBase DB = new MyDBase(DBUser.sserver, DBUser.DBName, DBUser.suser, DBUser.spasswd);
            int d1 = int.Parse(comboBox_Year.Text);
            int d2 = d1 + 1;
            DataSet DS = DB.GetRecordset("SELECT * FROM VIEW_EDUCATION_TRAIN where  培训时间 between ‘" + d1 + "‘ and ‘" + d2 + "‘ ");
            if (DB.ErrorCode())
            {
                MessageBox.Show(DB.ErrMessage(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            dataGridView2.DataSource = DS.Tables[0];
            DB.DBClose();
        }


comboBox绑定数据库后SelectedIndexChanged事件出错,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。