我已注册为我的数据库表。我想将用户输入的信息更新到我的 SQL Server 数据库中。但它不起作用,它不会发生任何错误,但数据键不会更新到我的数据库中。如果我的代码有任何问题,请有人帮助我?谢谢。
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=USER-PC;Initial Catalog=webservice_database;Integrated Security=True");
SqlCommand cmd = new SqlCommand("UPDATE registration SET username = @username, password = @password, retypepassword = @retypepassword, gender = @gender, birth = @birth, address = @address, city = @city, country = @country, postcode = @postcode, email = @email, carno = @carno", con);
con.Open();
cmd.Parameters.AddWithValue("@username", TextBoxUsername.Text);
cmd.Parameters.AddWithValue("@password", TextBoxPassword.Text);
cmd.Parameters.AddWithValue("@retypepassword", TextBoxRPassword.Text);
cmd.Parameters.AddWithValue("@gender", DropDownListGender.Text);
cmd.Parameters.AddWithValue("@birth", DropDownListDay.Text);
cmd.Parameters.AddWithValue("@address", TextBoxAddress.Text);
cmd.Parameters.AddWithValue("@city", TextBoxCity.Text);
cmd.Parameters.AddWithValue("@country", DropDownListCountry.Text);
cmd.Parameters.AddWithValue("@postcode", TextBoxPostcode.Text);
cmd.Parameters.AddWithValue("@email", TextBoxEmail.Text);
cmd.Parameters.AddWithValue("@carno", TextBoxCarno.Text);
cmd.ExecuteNonQuery();
con.Close();
if (IsPostBack)
{
Response.Redirect("UpdateSuccess.aspx");
}
在我单击确认后,它以某种方式仅更新我gender
的从男性到女性的列,其他数据列不会更新。