上一个文件接口在   DataNavigateUrlFormatString="detail.aspx? id = {0}"   detail.aspx:<script language="c#" runat="server">
  DataRow dr;
  DataSet ds;
  string newsid;
  void Page_Load(object sender,EventArgs e)
  { SqlConnection MyConnection;
string strCon;

newsid = Request.QueryString["id"]; MyConnection = new SqlConnection("server = LST-PC;database = data;uid = sa;pwd = ''");
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();
  }
  </script>
..............报错是 '=' 附近有语法错误。 我觉得应该是  newsid = Request.QueryString["id"];
 接收的数据有问题 把 newsid 换成"1"就能跑了 不知道该怎么改  请高手指点

解决方案 »

  1.   

    id没有传过来或者传过来的id不是数字
      

  2.   

    id那里有错误。跟踪设个断点看下。运行后的sql语句就知道了。
      

  3.   

    ("server = LST-PC;database = data;uid = sa;pwd = ''");Server=LST-PC;database=data;uid=sa;pwd=''
      

  4.   

    newsid = Request.QueryString["id"].ToString();如果不能保证传过来的id是数字的话,为了防止sql注入,最好使用参数化语句或存储过程。。
      

  5.   

    问题已经解决  来 newsid = Request.QueryString.ToString(); 获取的值是 +id+=+1, 用
    Substring(6) 截取id数字  。            为什么会得到+id+=+1 有人知道么?  可加QQ315032109 谢谢。。