//查询 private void btnQueryEmp_Click(object sender, EventArgs e) { //按姓名查询 if (cmboxIdorName.SelectedIndex == 0) { dataGridView1.DataSource = null; var list = empBll.QueryByName(txtQueryCondition.Text.Trim()); if (list == null) { MessageBox.Show(NO_MESSAGE); return; } dataGridView1.DataSource = list; } //按工号查询 if (cmboxIdorName.SelectedIndex == 1) { Employee emp = empBll.QueryById(txtQueryCondition.Text.Trim().ToUpper()); if (emp == null) { MessageBox.Show(NO_MESSAGE); return; } List <Employee> list = new List <Employee>(); list.Add(emp); dataGridView1.DataSource = null; dataGridView1.DataSource = list; } }