概述
1、思维导图
2、声明并实例化SQL数据适配器,同时借助构造函数,将其SelectCommand属性设为先前创建的SQL命令
将SQL数据适配器的查询命令属性指向SQL命令
声明并实例化数据表,以用作下拉框数据源
SQL数据适配器读取数据,并填充数据表
将下拉框的显示成员设为数据表的名称列
调用SQL命令的方法ExecuteReader来执行命令,并获取数据阅读器
在数据阅读器的索引器中指定列名,从而访问当前记录的指定列的值,并赋予相应控件
3、
public frm_doctorinformation() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { SqlConnection sqlConnection = new SqlConnection(); sqlConnection.ConnectionString = "Server=(local);Database=医院门诊预约管理系统;Integrated Security=sspi"; SqlCommand sqlCommand = new SqlCommand(); SqlCommand sqlCommand1 = new SqlCommand(); SqlCommand sqlCommand2 = new SqlCommand(); sqlCommand.Connection = sqlConnection; sqlCommand1.Connection = sqlConnection; sqlCommand2.Connection = sqlConnection; sqlCommand.CommandText = "SELECT * FROM tb_doctorTitle;"; sqlCommand1.CommandText = "SELECT * FROM tb_Department;"; sqlCommand2.CommandText = "SELECT * FROM tb_doctor WHERE No_hospital=@No_hospital AND No_doctor=@No_doctor"; sqlCommand2.Parameters.AddWithValue("@No_doctor", this.txb_Nodoctor.Text); sqlCommand2.Parameters.AddWithValue("@No_hospital", this.txb_Nohospital.Text); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(); SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter(); sqlDataAdapter.SelectCommand = sqlCommand; sqlDataAdapter1.SelectCommand = sqlCommand1; DataTable tb_doctorTitle = new DataTable(); DataTable tb_Department = new DataTable(); sqlConnection.Open(); sqlDataAdapter.Fill(tb_doctorTitle); sqlDataAdapter1.Fill(tb_Department); this.cmb_title.DataSource = tb_doctorTitle; this.cmb_Department.DataSource = tb_Department this.cmb_Department.DisplayMember = "Name"; this.cmb_title .DisplayMember = "Title"; this.cmb_title .ValueMember = "No_doctorTitle"; this.cmb_Department.ValueMember = "No"; SqlDataReader sqlDataReader = sqlCommand2.ExecuteReader(); if (sqlDataReader.Read()) { this.txb_Namedoctor .Text = sqlDataReader["Name_doctor"].ToString(); this.dtp_employDate.Value = (DateTime)sqlDataReader["BirthDate_doctor"]; this.rdb_doctorMale.Checked = (bool)sqlDataReader["Gender_doctor"]; this.rdb_doctorFemale .Checked = !(bool)sqlDataReader["Gender_doctor"]; this.dtp_BirthdateDoctor .Value = (DateTime)sqlDataReader["BirthDate_doctor"]; this.cmb_title.SelectedValue = (int)sqlDataReader["TitleNo"]; this.cmb_Department.SelectedValue = (int)sqlDataReader["Department_No"]; this.txb_Graduatedoctor.Text = sqlDataReader["Graduate_doctor"].ToString(); this.txb_Remaindoctor.Text = sqlDataReader["Remain_Doctor"].ToString(); } sqlDataReader.Close(); }
当输入医生编号以及医院标识码时,点击查询将查询到医生的具体信息
转载于:https://www.cnblogs.com/ZQHHP/p/9806471.html
最后
以上就是碧蓝苗条为你收集整理的学习笔记:如何在C#各类控件中输入/输出数据的全部内容,希望文章能够帮你解决学习笔记:如何在C#各类控件中输入/输出数据所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复