查看医生信息并修改

知识点描述:

管理员登录后对医生信息的录入;查看医生的信息功能

思维导图:

示例代码:

SqlConnection sqlConnection = new SqlConnection(); //声明并实例化SQL连接;
sqlConnection.ConnectionString =
"Server=(local);Database=AddressList;Integrated Security=sspi"; //在字符串变量中,描述连接字符串所需的服务器地址、数据库名称、集成安全性(即是否使用Windows验证);
SqlCommand sqlCommand = new SqlCommand(); //声明并实例化SQL命令;
SqlCommand sqlCommand2 = new SqlCommand(); //声明并实例化SQL命令;
sqlCommand.Connection = sqlConnection; //将SQL命令的连接属性指向SQL连接;
sqlCommand2.Connection = sqlConnection; //将SQL命令的连接属性指向SQL连接;
sqlCommand.CommandText = "SELECT * FROM tb_Doctoroffice;"; //指定SQL命令的命令文本;该命令查询所有班级,以用作下拉框数据源;
sqlCommand2.CommandText = "SELECT * FROM tb_Doctor WHERE DoctorNo=@DoctorofficeNo;"; //指定SQL命令的命令文本;该命令查询指定学生;
sqlCommand2.Parameters.AddWithValue("@DoctorofficeNo", "3160707001"); //向SQL命令的参数集合添加参数的名称、值;
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(); //声明并实例化SQL数据适配器,同时借助构造函数,将其SelectCommand属性设为先前创建的SQL命令;
sqlDataAdapter.SelectCommand = sqlCommand; //将SQL数据适配器的查询命令属性指向SQL命令;
DataTable DoctorTable = new DataTable(); //声明并实例化数据表,用于保存所有班级,以用作下拉框数据源;
sqlConnection.Open(); //打开SQL连接;
sqlDataAdapter.Fill(DoctorTable); 
this.cmb_Doctoroffice.DataSource = DoctorTable; 
this.cmb_Doctoroffice.DisplayMember = "DoctorofficeName"; 
this.cmb_Doctoroffice.ValueMember = "DoctorofficeNo"; 
SqlDataReader sqlDataReader = sqlCommand2.ExecuteReader(); //调用SQL命令的方法ExecuteReader来执行命令,并获取数据阅读器;
if (sqlDataReader.Read()) //若数据阅读器成功读取到下一条记录(首次查询则表示第一条记录);
{
this.txb_No.Text = sqlDataReader["DoctorNo"].ToString(); //在数据阅读器的索引器中指定列名,从而访问当前记录的指定列的值,并赋予相应控件;
this.txb_Name.Text = sqlDataReader["DoctorName"].ToString();
this.rdb_Male.Checked = (bool)sqlDataReader["Gender"];
this.rdb_Female.Checked = !(bool)sqlDataReader["Gender"];
this.dtp_BirthDate.Value = (DateTime)sqlDataReader["BirthDate"];
this.cmb_Doctoroffice.SelectedValue = (int)sqlDataReader["DoctorofficeNo"];
this.txb_Speciality.Text = sqlDataReader["Speciality"].ToString();
}
sqlDataReader.Close(); //关闭数据阅读器(同时关闭连接);
}
}

效果截图:

 

posted @ 2018-10-25 00:42  太阳公公是暖光!  阅读(224)  评论(0编辑  收藏  举报