I'm going to try ONE MORE TIME to get this forum to accept the formatting I want to use!!!
Oh, sorry! I misread your code, somewhat. I thought you were going to always use your Get_CommentCount to get the counts, one blog entry at a time.
I see now that you just have made the mistake of not trusting SQL Server to do the right thing.
You can GET RID of your Get_CommentCount funtion, entirely, and rewrite the other function thus:
Code:
Public Function Increment_CommentCount(ByVal blogEntryId As Integer) As Integer
Return CINT( SqlHelper.ExecuteScalar( _
_constring, _
CommandType.Text, _
"Update BlogEntry set commentcount=commentcount+1 where id= @blogEntryId; " & _
"SELECT commentcount WHERE id=@blogEntryId;", _
New SqlParameter("@blogEntryId", blogEntryId), _
New SqlParameter("@blogEntryId", blogEntryId) _
) )
End Function
But better, of course, would be to create a simple SP to do that:
Code:
Create Procedure IncrementCommentCount( @id INT )
AS
SET NOCOUNT ON -- probably don't need this...won't hurt
UPDATE BlogEntry set commentcount=commentcount+1 where id = @id
SET NOCOUNT OFF
SELECT commentcount WHERE id=@id
And then your
VB code is reduced to as simple as perhaps:
Code:
Public Function Increment_CommentCount(ByVal blogEntryId As Integer) As Integer
Return CINT( SqlHelper.ExecuteScalar( _
_constring, _
CommandType.Text, _
"EXECUTE IncrementCommentCount " & blogEntryId _
) )
End Function
All untested and I'm writing in this little tiny textarea window, so forgive typos. But hopefully you get the idea.
And I *STILL* think you'd be better off incorporating the increment into a SP where you INSERT the comment into the comments table.