医院信息系统点击科室切换科室医生
页面启动:(private void Reg_Load(object sender, EventArgs e)
)
//获取医生 默认内科的医生
update_combox_doctor(comboBox2.Text.Trim());
封装函数,方便复用
//切换科室, 获取医生信息
public void update_combox_doctor(String officeName)
{
try
{
//连接查询
//select a.staffID,a.name from staffInfor a inner join officeInfor b on a.officeID = b.officeID where b.officeName = '内科'
string sql_doc = string.Format("select a.staffID,a.name from staffInfor a inner join officeInfor b on a.officeID = b.officeID where b.officeName = '{0}'",officeName);
SqlCommand cmd = new SqlCommand(sql_doc, DBConn.conn);
DBConn.conn.Open()
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
this.comboBox3.Items.Add("[" + dr[0].ToString() + "]" + dr[1].ToString())
//显示效果:[181200000]李明
}
dr.Close();
catch (Exception ex)
{
Console.WriteLine(ex.Message)
}
finally
{
DBConn.conn.Close();
}
}
函数使用
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
// 先清空
comboBox3.Text = "";
comboBox3.Items.Clear();
update_combox_doctor(comboBox2.Text.Trim());
//comboBox2.Text
}