“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------第 1 行: '17' 附近有语法错误。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '17' 附近有语法错误。源错误: 执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。  堆栈跟踪: 
[SqlException (0x80131904): 第 1 行: '17' 附近有语法错误。]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857370
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734982
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
   System.Data.SqlClient.SqlDataReader.get_MetaData() +62
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +886
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
   System.Data.SqlClient.SqlCommand.ExecuteScalar() +137
   UHDisPage.UhDisPageRepeaterPost.GetRecordCount() +117
   UHDisPage.UhDisPageRepeaterPost.OnLoad(EventArgs e) +106
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Control.LoadRecursive() +131
   System.Web.UI.Control.LoadRecursive() +131
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061 
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.210

解决方案 »

  1.   

    发生错误页的.cs代码如下:using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;public partial class newsList : System.Web.UI.Page
    {
        string sqlTemp = "Where 1=1";   
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["tontelConn"].ToString());
        protected void Page_Load(object sender, EventArgs e)
        {
            string typeText = Request.QueryString["TypeID"].ToString();
            SqlDataAdapter sda = new SqlDataAdapter("Select ID,Title,Type,CreateDate From TC_News Where Type= '"+typeText+"'  Order By CreateDate Desc", conn);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            Repeater1.DataSource = ds.Tables[0];
            //以下部分到 this.DataBind(sqlTemp)有问题.我的想法是:当获取不同的URL参数就会显示相应类型的新闻.        
            switch (typeText)
            {
                case "17":
                    sqlTemp += " and 17";
                    break;
                case "34":
                    sqlTemp += " and 34";
                    break;
                case "35":
                    sqlTemp += " and 35";
                    break;
                case "36":
                    sqlTemp += " and 37";
                    break;
            }        this.DataBind(sqlTemp);//可以加入" where a=b ..." 条件
            sda.Dispose();
            ds.Dispose();
            conn.Close();
        }
        void DataBind(string tmpSql)
        {
            pagination.DBControl = Repeater1;
            pagination.SqlConn = conn;
            pagination.SqlString = "Select * From TC_News" + tmpSql + " Order By CreateDate Desc";
            pagination.SqlRecordCountString = "Select Count(*) From TC_News " + tmpSql;
        }}
      

  2.   

    1.SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["tontelConn"].ConnectionString;
    2.sqlTemp += " and 17";
    你看看sql变成什么了啊
    Select * From TC_News where 1=1 and 17 Order By CreateDate Desc17前面是不是缺少字段名称呢
      

  3.   

    LS说的没错,在动态生成SQL语句少了字段名,看LZ说根据新闻类别来显示,那case里应该是
    sqlTemp += " and typeid=17";
      

  4.   

    先谢谢楼的朋友.大哥来的不晚,我先按楼上朋友说的处理了,但出现了新的问题.请高手续继帮我解决,我今晚一定要把这个问题搞好,明天我上班老板看啊.第 1 行: '1' 附近有语法错误。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '1' 附近有语法错误。源错误: 执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。  堆栈跟踪: 
    [SqlException (0x80131904): 第 1 行: '1' 附近有语法错误。]
       System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857370
       System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734982
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
       System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
       System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
       System.Data.SqlClient.SqlDataReader.get_MetaData() +62
       System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
       System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +886
       System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
       System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
       System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
       System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
       System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +7
       System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +141
       System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137
       System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable) +92
       UHDisPage.UhDisPageRepeaterPost.FillData() +210
       UHDisPage.UhDisPageRepeaterPost.OnLoad(EventArgs e) +442
       System.Web.UI.Control.LoadRecursive() +47
       System.Web.UI.Control.LoadRecursive() +131
       System.Web.UI.Control.LoadRecursive() +131
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061 
    --------------------------------------------------------------------------------
    版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.210