效果图:设置只读:文本框属性—>ReadOnly为true即可(性别框可以用textbox,毕竟是根据身份证获取到的,不可以更改)

点击提交按钮,将数据存到后端数据库
/// <summary>
/// 提交按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString = "Server=(local);Database=OnLine;Integrated Security=sspi";
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlConnection;
sqlConnection.Open();
sqlCommand.CommandText =
$"INSERT tb_Years(No,ID,dateTime,Yearss,Gender)"
+ $"VALUES"
+ $"('{this.textBox1.Text.Trim()}','{this.textBox2.Text.Trim()}','{this.textBox3.Text.Trim()}','{this.textBox4.Text.Trim()}','{this.comboBox1.Text.Trim()}')";
Object obj = sqlCommand.ExecuteScalar();
sqlConnection.Close();
sqlCommand.Clone();

本文介绍如何在C#中根据身份证号码获取用户的生日和性别,并将其显示在文本框中。同时,展示了如何计算并显示用户的年龄。在用户提交信息后,数据会被保存到后端数据库。
最低0.47元/天 解锁文章
7433

被折叠的 条评论
为什么被折叠?



