Last post Apr 15, 2012 10:17 AM by PGChoudhury
Apr 14, 2012 08:16 AM|PGChoudhury|LINK
I am working on a forum application using C# and ASP.Net with SQL Server 2005 as backend. I have developed several modules like creating forums and creating topics and posting replies to topics. But I am stuck with a problem. I need to update the views count
of the corresponding topics everytime a user visits it and save the changes in the database. I have a table called 'ForumTopics' which contains a column 'ViewCount'. I need some idea on how to update the viewcount spontaneously. I think it has a lot to do
with state management techniques and similar stuff like Triggers. But I simply cannot fathom how to achieve the same.
Please help me on this subject as I am stuck with the development. Look forward to receiving some active help on this matter.
Many Thanks in anticipation.
Apr 14, 2012 11:15 AM|PGChoudhury|LINK
This is my database structure--
I am using a formatted datalist control to show the forums and forum topics. In the datalist I have bound the topicid to the topic icon image in the control.
Apr 15, 2012 10:17 AM|PGChoudhury|LINK
Resolved the issue myself. Used a stored procedure to update the viewcount value in the table everytime a user clicks a thread and views it. Just passed the topicid to the procedure as a parameter to specify which topic to update.
here is the procedure --
Create procedure [dbo].[sproc_UpdateViewCount]
declare @viewcount bigint
select @viewcount=ViewCount from ForumTopics where TopicID=@TopicID
update ForumTopics set ViewCount=@ViewCount where TopicID=@TopicID