Click here to Skip to main content
15,914,905 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is the code in classic asp:
ASP
set con=Server.CreateObject("ADODB.Connection")
con.Open strcon
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM category where news_allow=1",con,0,1 
		
do while not rs.eof
	news_visit=0
	set rst=Server.CreateObject("ADODB.Recordset")
	rst.Open "SELECT news_visit FROM news_list where news_ID="&rs("news_ID")&" and news_status=1",con,0,1 
				
	do while not rst.eof
        news_visit=rst("news_visit")+news_visit
	rst.MoveNext
        loop	
set rst=nothing

The page contain news category and under the category it display how many news are there and how many times hit this category news. I want this code in C#. If user click the news under the category then the news_visit counter is +1.

Please any one can help me how can I do this.

Thanks in advance
Posted
Updated 9-Jun-11 5:16am
v3

While the question you are asking is somewhat vague, I think I may be able to help.

When you want to store hits across your entire application in ASP.NET, you should use an application level variable. These work the same way as session variables except (you guessed it) they don't expire at the end of a session. They WILL however reset when the application is restarted/terminated.

If you do not care if the numbers reset upon an application restart, then use an application level variable. Attach an event handler to the click event of the linkbutton, button, or whatever button you choose to use that will increment the application variable by one. Here is a tutorial on application level variables: http://weblogs.asp.net/albertpascual/archive/2010/03/01/difference-between-asp-net-sessions-application-variables-and-cache-objects.aspx[^]

If you DO care if the numbers reset upon an application restart (or if your application is going to be running on multiple servers) then you should take the same approach as previously mentioned but instead of using application state to store your value, use a database system to push/pull the variables.

Hope this helps

-Moarcodeplz
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900