第 1 行: '=' 附近有语法错误。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。源错误: 
行 29:  DataSet ds=new DataSet();
行 30:  myCommand.Fill(ds,"Contents");
行 31:  dr=ds.Tables["Contents"].Rows[0];
行 32: 
行 33:  SqlCommand myCommand2=new SqlCommand("select click from Contents where id="+newsid,myConnection);
 源文件: f:\xujie\xinwen\shownews.aspx.cs    行: 31 
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace xinwen
{
/// <summary>
/// shownews 的摘要说明。
/// </summary>
public class shownews : System.Web.UI.Page
{
public DataRow dr;
protected System.Web.UI.WebControls.AdRotator Adrotator1;
public String newsid;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
newsid=Request.Params["id"];
SqlConnection myConnection=new SqlConnection("Initial Catalog=xinwen;Data Source=(local);User ID=sa;Password=admin");
SqlDataAdapter myCommand=new SqlDataAdapter("SELECT * FROM Contents WHERE id="+newsid,myConnection);
DataSet ds=new DataSet();
myCommand.Fill(ds,"Contents");
dr=ds.Tables["Contents"].Rows[0]; SqlCommand myCommand2=new SqlCommand("select click from Contents where id="+newsid,myConnection);
myCommand2.Connection.Open();
SqlDataReader reader=myCommand2.ExecuteReader();
reader.Read();
int i=reader.GetInt32(0);
i++;
reader.Close();
myCommand2.CommandText="update contents set click="+i.ToString()+"where id="+newsid;
myCommand2.ExecuteNonQuery();
myCommand2.Connection.Close();
myConnection.Close();
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.Load += new System.EventHandler(this.Page_Load); }
#endregion protected string FormatString(string str)
{
str=str.Replace(" ","&nbsp;&nbsp;");
str=str.Replace("<","&lt;");
str=str.Replace(">","&gt;");
str=str.Replace('\n'.ToString(),"<br>");
return str;
}
}
}
<%@ Page language="c#" Codebehind="shownews.aspx.cs" AutoEventWireup="false" Inherits="xinwen.shownews" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>显示新闻</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>
<link rel="stylesheet" href="Style.css" type="text/css">
<body bgcolor="#FFFFFF" text="#000000">
<table width="90" border="0" align="center">
<tr>
<td>
<div align="center"><asp:adrotator AdvertisementFile="ads.xml" BorderColor="black" BorderWidth="0" runat="server" /></div>
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</table>
<table width="98%" border="1" cellspacing="0" cellpadding="0" bordercolordark="#ffffff"
bordercolorlight="#006b9f" align="center">
<tr>
<td>
<table width="100%" border="0">
<tr>
<td><font color="#ff8000">我的新闻</font></td>
<td><div align="right"><img src="printer.gif" width="16" height="14"> <a href="Javascript:window.print()">
打印本页</a></div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="35">
<table width="100%" border="0">
<tr>
<td><div align="center"><font size="3"><b><%=FormatString(dr["biaoti"].ToString()).ToString() %></b></font></div>
</td>
</tr>
<tr>
<td><div align="center"><%if (dr["img"].ToString()!=""){%><img src='file/<%=dr["img"] %>'><%}%></div>
</td>
</tr>
<tr>
<td><%=FormatString(dr["neirong"].ToString()).ToString() %>
</td>
</tr>
<tr>
<td><div align="right"><%=dr["shijian"] %></div>
</td>
</tr>
<tr>
<td><div align="right"><FONT face="宋体"></FONT><%=FormatString(dr["zuozhe"].ToString()).ToString() %></div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><table width="100%" border="0">
<tr>
<td width="24%"><font color="#0000ff">浏览</font><font color="red"><%=dr["click"] %></font><font color="#0000ff">次</font></td>
<td width="50%">
<div align="center"><img src="email.gif"><img src="g.gif" width="17" height="13"></div>
</td>
<td width="26%"><div align="right"><a href="Javascript:window.close()">关闭窗口</a></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</HTML>

解决方案 »

  1.   

    have a trypublic DataRow dr ;
    dr = ds.Tables["Contents"].Rows.NewRow();
      

  2.   

    public DataRow dr ;
    这个我定义的是全局变量!dr =ds.Tables["Contents"].Rows.NewRow();
    修改后还是 异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。
      

  3.   

    试试看
    SqlDataAdapter myCommand=new SqlDataAdapter("SELECT * FROM Contents WHERE id='"+newsid+"'",myConnection);
      

  4.   

    首先保证连接已打开
    然后看你的ID是否包含非数字字符,如果包含则需要加上单引号
    最后看是否有数据,没有数据,引用row[0]会有问题
      

  5.   

    SqlDataAdapter myCommand=new SqlDataAdapter("SELECT * FROM Contents WHERE id='"+newsid+"'",myConnection);
    三处地方都改了,还是异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。可以肯定数据库里是有数据的.数据库连接也是打开的.郁闷啊.
      

  6.   

    如果是这样,那你测试一下row[0]是否是null
    用断点调试一下,看看
    if(ds.Tables["Contents"].Rows[0] == null)
    {
    ///
    }
    else
    {
    }
      

  7.   

    异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。源错误: 
    行 29:  DataSet ds=new DataSet();
    行 30:  myCommand.Fill(ds,"Contents");
    行 31:  if(ds.Tables["Contents"].Rows[0] == null)
    行 32: {
    行 33: ///
     源文件: f:\xujie\xinwen\shownews.aspx.cs    行: 31
      

  8.   

    System.Data.SqlClient.SqlException错误,肯定是你的sql有问题或者连接根本没有打开
    你再试试
    if(myConnection.State == System.Data.ConnectionState.Closed)
    {
    myConnection.Open();
    }
    看看是不是连接字符串的问题
      

  9.   

    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。源错误: 
    行 29:  DataSet ds=new DataSet();
    行 30:  myCommand.Fill(ds,"Contents");
    行 31: if(myConnection.State == System.Data.ConnectionState.Closed)
    行 32: {
    行 33: myConnection.Open();
     源文件: f:\xujie\xinwen\shownews.aspx.cs    行: 31
      

  10.   

    if(myConnection.State == System.Data.ConnectionState.Closed)判断加在myCommand.Fill之前
      

  11.   

    异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。源错误: 
    行 29:  DataSet ds=new DataSet();
    行 30: if(myConnection.State == System.Data.ConnectionState.Closed)
    行 31: {
    行 32: myConnection.Open();
    行 33: }
     
    源文件: f:\xujie\xinwen\shownews.aspx.cs    行: 31
      

  12.   

    SqlCommand myCommand2=new SqlCommand("select click from Contents where id='"+newsid+"'",myConnection);
      

  13.   

    SqlCommand myCommand2=new SqlCommand("select click from Contents where id="+newsid,myConnection);看看你的newsid的类型和数据库中  click的类型是否匹配?
      

  14.   

    SqlDataAdapter myCommand=new SqlDataAdapter("SELECT * FROM Contents WHERE id="+newsid,myConnection);
    在这一句调试一下看看.把完整的select语句复制到SQL中运行一下看看
      

  15.   

    无语了.我已经将所有我知道的可能都说出来了
    还是按照开始这个步骤
    1.保证连接打开,方式就是用刚才我给你的if判断
    2.连接字符串正确,检查newsid是否包含非数字字符,如果是需要单引号,这个我看你前面已经修改了
    3.保证数据库有数据,并且你写的sql语句正确,实在不行调试时将sql语句显示出来到查询分析器中运行.
    如果还是不行,那就很不幸了
      

  16.   

    SqlConnection myConnection=new SqlConnection("Initial Catalog=xinwen;Data Source=(local);User ID=sa;Password=admin");
    在这句下面写上
    if(myConnection.State == System.Data.ConnectionState.Closed)
    {
    myConnection.Open();
    }测试连接有没有问题
      

  17.   

    你重新编译了没有?iisrest一下
      

  18.   

    照样还是31行报错.......
    异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。源错误: 
    行 29: {
    行 30: myConnection.Open();
    行 31: }
    行 32:  SqlDataAdapter myCommand=new SqlDataAdapter("SELECT * FROM Contents WHERE id='"+newsid+"'",myConnection);
    行 33:  DataSet ds=new DataSet();
     源文件: f:\xujie\xinwen\shownews.aspx.cs    行: 31 测试别的程序一切正常,重启iis后还是一样....
      

  19.   

    再到C:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files下面删除所有文件
    重新编译,再看看
    我的是2k 系统,asp1.1的
      

  20.   

    .dll .pdb为后缀的删不掉...........
    就是我编辑的那个文件夹里的信息......倒死.....
      

  21.   

    删不掉需要重启iis
    并关闭vs试试
      

  22.   

    SqlCommand myCommand2=new SqlCommand("select click from Contents where id="+"'"+newsid+"'",myConnection);
      

  23.   


    Response.Write("select click from Contents where id="+newsid);
    把你的SQL语句单独输出来看看,照提示看就是SQL语句出错了
      

  24.   

    可能是request.params["id"]是空串