简体   繁体   English

sql表数据更新失败

[英]failure in Update of sql table data

I am trying to update users details if user want to edit his/her information on our system I use following code but I couldn't be able to do it. 如果用户想在我们的系统上编辑他/她的信息,我正在尝试更新用户详细信息,我使用以下代码,但无法执行。 There is no error or exception occur, even I add watch and code smoothly execute. 即使添加监视并平稳执行代码,也不会发生错误或异常。

public void updateprofile()
{

    SqlConnection MySQL = new SqlConnection(ConfigurationManager.ConnectionStrings["BloodDonorRegistrationConnectionString"].ToString());
    SqlCommand cmd = new SqlCommand("UPDATE Donor SET D_FirstName= @fn, D_LastName=@ln, D_Phone=@phn, D_City=@ct, D_Address=@add where D_Email='"+Session["UserID"]+"'", MySQL);
    cmd.CommandType = CommandType.Text;
    cmd.Parameters.AddWithValue("@fn", TextBoxFName.Text);
    cmd.Parameters.AddWithValue("@ln", TextBoxLName.Text);
    cmd.Parameters.AddWithValue("@phn", TextBoxCellNum.Text);
    cmd.Parameters.AddWithValue("@ct", DropDownListCity.SelectedItem.Text);
    cmd.Parameters.AddWithValue("@add", ButtonAddress.Text);
    MySQL.Open();
    cmd.ExecuteNonQuery();
    MySQL.Close();
    Response.Redirect("doDashboard.aspx");
}

Please guide and thanks in advance. 请指导并提前致谢。

Session["UserID"]是一个对象,但是我认为您数据库中的D_Email列是varchar类型,因此请在where子句中使用Session["UserID"].ToString()尝试一下Session["UserID"].ToString()它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM