效果图:设置只读:文本框属性—>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(