昨天的问题还没解决呀,麻烦大家再帮帮我好不:(
public DataRow dr;
public string newsid;
private void Page_Load(object sender, System.EventArgs e)
{
//创建数据库连接,获取新闻信息
newsid=Request.Params["id"];
string strConn =ConfigurationSettings.AppSettings["dsn"];
SqlConnection myConnection = new SqlConnection(strConn);
SqlDataAdapter myCommand = new SqlDataAdapter("SELECT * FROM news WHERE id='"+newsid+"'", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "news");
dr = ds.Tables["news"].Rows[0];
//获取新闻的点击率
SqlCommand myCommand2= new SqlCommand("select click from news where id='"+newsid+"'",myConnection);
myCommand2.Connection.Open();
SqlDataReader reader = myCommand2.ExecuteReader();
reader.Read();
int i = reader.GetInt32(0);
i = i + 1;
reader.Close();
//更新新闻的点击率
myCommand2.CommandText = "UPDATE news SET click = "+i.ToString()+" WHERE id= '"+newsid+"'";
myCommand2.ExecuteNonQuery();
myCommand2.Connection.Close();
myConnection.Close();
}