.net贴吧 怎么计算帖子点击数和回复数?

来源:百度知道 编辑:UC知道 时间:2024/06/20 15:27:37
问题同上~新人练习不会做了 大家帮帮忙 首页我用Gridview绑定的,连数据库,最好有代码~顺便解说下详细点,感激不尽!
数据库里有点击数 和 回复数的字段

在页面载入事件中加入:
SqlCommand sqlcmd =new SqlCommand("select <点击数字段> from <表> where id="+id,sqlctn);//选取原来的点击数
int oldv=(Int32)sqlcmd.ExecuteScalar();
SqlCommand cmd = new SqlCommand("update <点击数字段> set '"+(oldv+1).ToString() + "' where id=" + id, sqlctn);//更改值 变成原来点击数+1

同样.在回复贴子的地方把点击数字段改成回复的就得了