NewsShow.aspx.cs
资源名称:yjal.rar [点击查看]
上传用户:shjujing
上传日期:2022-07-28
资源大小:11244k
文件大小:2k
源码类别:
Email客户端
开发平台:
Visual C++
- using System;
- using System.Data;
- using System.Data.SqlClient;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class ShowNews : System.Web.UI.Page
- {
- DataSet ds;
- protected DataRow dr;
- String NewsID;
- protected void Page_Load(Object sender, EventArgs e)
- {
- SqlConnection MyConnection;
- String ConnStr, strCon;
- //取得地址栏传入的参数,读取与NewsID对应的新闻
- NewsID = Request.QueryString["NewsID"];
- MyConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["NewsConnectionString"].ConnectionString);
- MyConnection.Open();
- String strCom = "SELECT NewsID, biaoti ,zhaizi ,neirong,img,counter ,shijian FROM News where NewsID=" + NewsID;
- ds = new DataSet();
- SqlDataAdapter myDa = new SqlDataAdapter(strCom, MyConnection);
- myDa.Fill(ds, "News");
- //取得新闻的实际内容,在网页中用类似<%=dr["neirong"]%>的方法显示
- dr = ds.Tables["News"].Rows[0];
- //更新浏览次数
- strCon = "UPDATE news SET counter = counter+1 WHERE (NewsID= " + NewsID + ")";
- SqlCommand myCommand2 = new SqlCommand(strCon, MyConnection);
- myCommand2.CommandText = strCon;
- myCommand2.ExecuteNonQuery();
- MyConnection.Close();
- }
- }