-1

已解决:我想出了自己的问题。它按我想的那样工作。我只是没有阅读正确的行。

我正在尝试在表 [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()
4

1 回答 1

0

请通过设置断点参考finalkey的值!只有不更新的可能是,

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

另外的选择

手动设置 where 类值 Like where finalvalue="user1dec" 并检查它是否有效,然后你可以......

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

于 2013-02-12T03:33:06.507 回答