第六周学习笔记之如何在各类控件中输入/输出数据

一、思维导图

3170707049 吕晨  3170707060 沈凯林

二、知识点描述
数据输入/输出主要相关控件
①下拉框(ComboBox)
显示一个可编辑的文本框,其中包含一个允许值下拉列表。
cmb_SearchId.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
cmb_SearchId.AutoCompleteSource= AutoCompleteSource.ListItems;
②图片框(PictureBox)
指定支持事务处理初始化,允许用户加载图片。
输入
Using System.Drawing.Imaging; //包含图像处理功能;
③日历框(DateTimePick)
允许用户选择日期和时间,并以指定的格式显示该日期和时间。
输入
sqlCommand.Parameters.AddWithValue("@Birthday", this.dtp_birthday.Value);
输出
this.dtp_birthday.Value = (DateTime)sqlDataReader[“Birthday”];
④文本框(TextBox)
允许用户输入文本,并提供多行编辑和密码字符掩码功能。
输入
1|sqlCommand.Parameters.AddWithValue("@No", this.txt_no.Text.Trim());
输出
1|this.txt_no.Text = sqlDataReader[“No”].ToString();
⑤单选框(RadioButton)
当与其他单选按钮成对出现时,允许用户从一组选项中选择单个选项。
输入
sqlCommand.Parameters.AddWithValue("@Sex", (bool)(this.rdb_male.Checked));
输出
this.rdb_male.Checked = (bool)sqlDataReader[“Sex”];
this.rdb_remale.Checked = !(bool)sqlDataReader[“Sex”];
⑥标签(Label)
为控件提供运行时信息或说明性文字。
输入
sqlCommand.Parameters.AddWithValue("@No", this.lbl_no.Text.Trim());
输出
this.txt_no.lbl = sqlDataReader[“No”].ToString();

三、代码
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString =
“Server=(local);Database=Edubase2018;Integrated Security=sspi”;
SqlCommand sqlCommand = new SqlCommand();
SqlCommand sqlCommand2 = new SqlCommand();
sqlCommand.Connection = sqlConnection;
sqlCommand2.Connection = sqlConnection;
sqlCommand.CommandText = “SELECT * FROM tb_room;”;
sqlCommand2.CommandText = “SELECT * FROM tb_Patient WHERE R_no=@R_no;”;
sqlCommand2.Parameters.AddWithValue("@ID", “350921199303029877”);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
sqlDataAdapter.SelectCommand = sqlCommand;
DataTable roomTable = new DataTable();
sqlConnection.Open();
sqlDataAdapter.Fill(roomTable);
this.cmb_room.DataSource = roomTable;
this.cmb_room.DisplayMember = “R_name”;
this.cmb_room.ValueMember = “R_no”;
SqlDataReader sqlDataReader = sqlCommand2.ExecuteReader();
if (sqlDataReader.Read()) {
this.txb_ID.Text = sqlDataReader[“ID”].ToString();
this.txb_Name.Text = sqlDataReader[“Name”].ToString();
this.txb_bedno.Text = sqlDataReader[“bedno”].ToString();
this.txb_NO.Text = sqlDataReader[“MedicalRecordNo”].ToString();
this.txb_mno.Text = sqlDataReader[“AdmissionNo”].ToString();
this.txb_old.Text = sqlDataReader[“old”].ToString();
this.rdb_Male.Checked = (bool)sqlDataReader[“Gender”];
this.rdb_Female.Checked = !(bool)sqlDataReader[“Gender”];
this.dtp_Date.Value = (DateTime)sqlDataReader[“Time”];
this.cmb_room.SelectedValue = (int)sqlDataReader[“R_No”];
this.txb_address.Text = sqlDataReader[“Address”].ToString();
this.txb_content.Text = sqlDataReader[“diagnose”].ToString();
}
sqlDataReader.Close();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值