SQL更新实际上没有更新?完成

本文关键字:更新 完成 实际上 SQL | 更新日期: 2023-09-27 17:58:40

解决了:我解决了自己的问题。它像我想的那样工作。我只是没有读到正确的一行。

我正在尝试更新表[Profiles]中一行中的几列。运行此代码时,我没有收到任何错误,但它实际上并没有更新列。我以前从未使用过更新。我做错了什么。

string currentPage = Request.Url.ToString();
Uri myUri = new Uri(currentPage);
string position = HttpUtility.ParseQueryString(myUri.Query).Get("position");
string electionYear = HttpUtility.ParseQueryString(myUri.Query).Get("year");
var finalkey = Session["Userid"].ToString() + "^" + position + "^" + electionYear;
string sqlquery = "UPDATE [Profiles] SET Qualifications=@Qualifications, Platform=@Platform, FamilyLife=@FamilyLife, Website=@Website where FinalKey=@FinalKey";
SqlConnection conn = new SqlConnection(dbLocation);
SqlCommand comm = new SqlCommand(sqlquery, conn);
try
{
conn.Open();
comm.Parameters.AddWithValue("@FinalKey", finalkey);
comm.Parameters.AddWithValue("@Qualifications", qualificationsBox.Text);
comm.Parameters.AddWithValue("@Platform", platformBox.Text);
comm.Parameters.AddWithValue("@FamilyLife", familyBox.Text);
comm.Parameters.AddWithValue("@Website", candWebsiteBox.Text);
comm.ExecuteNonQuery();
}
catch { }
conn.Close()

SQL更新实际上没有更新?完成

请通过设置断点来参考finalkey的值!不更新的唯一可能是

没有找到与此最终值匹配的记录。

另一种选择

手动设置where class值,如where finalvalue="user1dec",并检查它是否有效,则u可以。。。。。。。。

var finalkey=Session["Userid"].ToString()+"^"+position+"^+electionYear