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("server=ADMIN-PC;database=news;uid=sa;pwd='123456'");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(); }
2 回答
阿波罗的战车
TA贡献1862条经验 获得超6个赞
这个肯定是SQL语句的错误
Select biaoti,zhaizi,neirong,img,counter,shijian from news where id=' "+ newsid+"'
Select counter from news where id=' "+ newsid+"'
Update news set counter=" + i.ToString() + "where (id=" + newsid + ")
前两条错了 在sql2005修改后之后通过
蝴蝶不菲
TA贡献1810条经验 获得超4个赞
strCon = "Update news set counter=" + i.ToString() + "where (id=" + newsid + ")";
在where前加一个空格
- 2 回答
- 0 关注
- 572 浏览
添加回答
举报
0/150
提交
取消