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();
}
}
I want to add a reputation to the user of 5 points for the comment he leaves in the thread..but it fails to update why?/... commentID does get a value and so the reputation paramater