private void FindDepartment() { try { //ds = new DataSet(); ds = new DataSet(); //创建sql查询 StringBuilder sb = new StringBuilder(); sb.AppendFormat(@"select d.did as '部门编号', d.dname as '部门名称', d.ddescription as '部门表述',e.ename as '部门设备',d.ddevicenums as '设备数量' from d_departments as d,e_device as e where e.eid = d.ddevice"); if (textBox_findDepartment.Text.Trim() != "") { sb.AppendFormat(" and d.dname like '%{0}%'", textBox_findDepartment.Text.Trim()); } //赋值 this.dataGridView_departmentList.DataSource = ds.Tables["Comminty"]; // 绑定数据源 //搜索条件 按照员工id排序 sb.AppendFormat(" order by d.did asc"); try { //执行数据库连接 MySqlDataAdapter adapter = new MySqlDataAdapter(sb.ToString(), dbUtil.Connection); if (adapter.ToString() != "") { //开始填充表格 adapter.Fill(ds, "Comminty"); this.dataGridView_departmentList.DataSource = this.ds.Tables["Comminty"]; } else { MessageBox.Show("没有这部门", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception) { MessageBox.Show("数据库操作错误", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception) { MessageBox.Show("数据库操作错误", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }