public void InsertUserReputation()
{
StringBuilder sb = new StringBuilder();
sb.Append("UPDATE u ");
sb.Append(" SET u.Reputation = (u.Reputation + @Reputation)");//Problem is here u.Reputation is "Null" not 0... I think i need some if statement to check if it is a null and then update it to 0 and then add..what do you think?
sb.Append(" FROM Users u");
sb.Append(" INNER JOIN Comments c ON c.UsersID = u.UsersID");
sb.Append(" WHERE c.CommentsID = @CommentsID");
using (SqlConnection conn = new SqlConnection(AllQuestionsPresented.connectionString))
{
SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
cmd.Parameters.Add("@Reputation", SqlDbType.Int).Value = 5;
cmd.Parameters.Add("@CommentsID", SqlDbType.Int).Value = commentID;
conn.Open();
cmd.ExecuteNonQuery();
}
}
我想给用户添加一个信誉给5分的用户,他留在线程中的评论..但它无法更新为什么?/ ... commentID确实得到一个价值等信誉参数SQL更新语句添加一个值
(你不需要为该语句使用StringBuilder,顺便说一句 - 这只是增加了一小部分开销,但更重要的是:它使得代码不必要的复杂) –
是'u.Reputation' null的任何机会? –
你得到的错误是什么?或者它运行,但没有错误?请详细说明。 – Cortright