帮忙找原因:Gridview访问数据源失败

beibeisky 2008-10-16 05:52:29
我的程序里,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;
...全文
50 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
beibeisky 2008-11-12
  • 打赏
  • 举报
回复
非常抱歉,因工作很长时间没来照顾帖子.
问题已经解决了,是出在where附近没有空格,谢谢大家
guying999 2008-10-16
  • 打赏
  • 举报
回复
两个“where”前面加个空格“ where”试试,另外可以跟踪一下看看最终的SQL是什么。
dddd218 2008-10-16
  • 打赏
  • 举报
回复
sql语句有错,与gridview无关。
你检查自己的sql语句是否存在错误
emile02220 2008-10-16
  • 打赏
  • 举报
回复
你把这个SQL语句拿到查询分析器里执行了看看
emile02220 2008-10-16
  • 打赏
  • 举报
回复
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”前面加个空格试了看看~
sharpblade 2008-10-16
  • 打赏
  • 举报
回复
你可以查看一下最终的sql语句是什么.
关键字 'in' 附近有语法错误
可能是in(里面没有值)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧