点击率的代码怎么写
新闻页面的思路是这样:在载入页面的时候直接从数据库中取得标题、内容等信息,同时将点击率(newsClick)加1并存入数据库,请问一下应该怎么完成增加点击率的代码。
我看了一下以前的文章,有人说在数据库中写个存储过程,让新闻读取一次点击率加1,这样的存储过程又如何来实现呢?
protected void Page_Load(object sender, EventArgs e)
{
String connStr;
connStr = ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString;
SqlConnection Conn = new SqlConnection(connStr);
Conn.Open();
String strSQL = "SELECT newsTitle, newsClick, newsContent, newsTime FROM NEWS WHERE newsId = " + Request["newsId"];
SqlCommand Conmm = new SqlCommand(strSQL, Conn);
SqlDataReader dr = Conmm.ExecuteReader();
while (dr.Read())
{
String n_title = dr["newsTitle"].ToString();
String n_time = dr["newsTime"].ToString();
String n_click = dr["newsClick"].ToString();
String n_content = dr["newsContent"].ToString();
title.Text = (n_title);
time.Text = (n_time);
click.Text = (n_click);
content.Text = (n_content);
}
Conn.Close();
}