|
C#版的网站新闻发布系统(5) 〈%@Page language="C#" Debug="True"%〉 〈%@Import Namespace="System.Data"%〉 〈%@Import Namespace="System.Data.SqlClient"%〉 〈html〉 〈head〉 〈title〉新闻发布系统〈/title〉 〈style type="text/css"〉 〈!-- TABLE { FONT-SIZE: 9pt } INPUT { FONT-SIZE: 9pt } SELECT{ FONT-SIZE: 9pt } BODY { FONT-SIZE: 9pt } a:link { color: #000099; text-decoration: none} a:visited { color:#000099; text-decoration: none} a:hover { color: #990000; text-decoration: underline} td {font-size:9pt;line-height:13pt;} .p1 { font-family: "宋体"; font-size: 9pt} .p2 { } .p3 { font-family: "宋体"; font-size: 12pt} --〉 〈/style〉 〈script Language="C#" runat="server"〉 DataSet ds; DataRow dr; String newsid; void Page_Load(Object sender,EventArgs e) { SqlConnection MyConnection; String ConnStr,strCon; newsid = Request.Params["id"]; MyConnection =new SqlConnection("Initial Catalog=mydb;Data Source=netfiresoft;Integrated Security=SSPI;"); MyConnection.Open(); String strCom= "SELECT biaoti ,zhaizi ,neirong,img,counter ,shijian FROM news where id="+newsid; ds= new DataSet(); SqlDataAdapter myCommand=new SqlDataAdapter(strCom,MyConnection); myCommand.Fill(ds,"news"); dr = ds.Tables["news"].Rows[0]; strCon ="SELECT counter FROM news WHERE id = "+newsid; SqlCommand myCommand2= new SqlCommand(strCon, MyConnection); SqlDataReader reader = myCommand2.ExecuteReader(); reader.Read(); int i = reader.GetInt32(0); i++; reader.Close(); strCon ="UPDATE news SET counter = "+i.ToString()+" WHERE (id= "+newsid+")"; myCommand2.CommandText = strCon; myCommand2.ExecuteNonQuery(); MyConnection.Close();
|