第 1 行: '=' 附近有语法错误。

说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '=' 附近有语法错误。

源错误:

行 37: string Cat_Name="";
行 38: string strSql = "select * from Column_Cats where Column_Cat_ID=" + Cat_ID;
行 39: DataTable dt = DBC.getTable(strSql, "Column_Cats");
行 40: if (dt.Rows.Count > 0)
行 41: {

源文件: d:\vhostroot\localuser\dfyichu\www\App_Code\ColumnCat.cs 行: 39

堆栈跟踪:

[SqlException (0x80131904): 第 1 行: '=' 附近有语法错误。]
Sifung.DB.DBCommon.returnDS(String sql, String Table) +449
Sifung.DB.DBCommon.getTable(String sql, String Table) +68
ColumnCat.GetCatNameByCatID(String Cat_ID) in d:\vhostroot\localuser\dfyichu\www\App_Code\ColumnCat.cs:39
news.BindLeftMenu(Int32 fatherId, Int32 trId, Label labelText, String linkText) in d:\vhostroot\localuser\dfyichu\www\news.aspx.cs:109
news.ContentInitialize() in d:\vhostroot\localuser\dfyichu\www\news.aspx.cs:59
BasePage.PageInitialize() in d:\vhostroot\localuser\dfyichu\www\App_Code\BasePage.cs:26
news.Page_Load(Object sender, EventArgs e) in d:\vhostroot\localuser\dfyichu\www\news.aspx.cs:21
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.3603; ASP.NET 版本:2.0.50727.3082

string strSql = "select * from Column_Cats where Column_Cat_ID=" + Cat_ID;
你把你这条语句拿到查询分析器里面 执行一下 那个错误是SQL语句有问题与程序无关。你看看那个Column_Cat_ID是不是字符型大阿,如果是就在Cat_ID前后加上单引号。 最好不要用这种拼接的语句容易错不说还不安全,最好用Parameter来实现。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-11-06
你加点代码截取下得到的SQL查询语句strSql
后面的先注释掉
相似回答