我的程序里,Gridview无法读出需要的数据,浏览器报错如下: 
 Server Error in '/All Together' Application.
--------------------------------------------------------------------------
关键字 'in' 附近有语法错误。
'=' 附近有语法错误。 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: 关键字 'in' 附近有语法错误。
'=' 附近有语法错误。
     而对应地方的代码是这样的,到底哪个地方错了,望高手赐教
 string strCommand = "select ProductID,Name,ProductNumber,ListPrice from Production.Product";
        strCommand += "where ProductSubCategoryID in ";
        strCommand += "(select ProductSubcategoryID from Production.ProductSubcategory";
        strCommand += "where ProductCategoryID = @ProductCategoryID)";
        SqlProducts.SelectCommand = strCommand;

解决方案 »

  1.   

    你可以查看一下最终的sql语句是什么.
    关键字 'in' 附近有语法错误
    可能是in(里面没有值)
      

  2.   

    string strCommand = "select ProductID,Name,ProductNumber,ListPrice from Production.Product"; 
            strCommand += "where ProductSubCategoryID in "; 
            strCommand += "(select ProductSubcategoryID from Production.ProductSubcategory"; 
            strCommand += "where ProductCategoryID = @ProductCategoryID)";  “where”前面加个空格试了看看~ 
      

  3.   

    你把这个SQL语句拿到查询分析器里执行了看看 
      

  4.   

    sql语句有错,与gridview无关。
    你检查自己的sql语句是否存在错误
      

  5.   

    两个“where”前面加个空格“ where”试试,另外可以跟踪一下看看最终的SQL是什么。
      

  6.   

    非常抱歉,因工作很长时间没来照顾帖子.
    问题已经解决了,是出在where附近没有空格,谢谢大家